您的位置:首页 > 其它

UVA 11859 - Division Game (SG博弈)

2013-08-22 10:14 375 查看
题目地址:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=226&problem=2959&mosmsg=Submission+received+with+ID+12234894

题意:给你n*m的矩阵,两个人轮流操作,每个人可以选一行中至少一个大于1的数变成它的真因子,直到一个人不能操作为输。(即:全为1)

题解:考虑每一个数的素因子个数,比如12=2*2*3,包含三个素因子,可以拿掉三次,所以可以装换为Nim游戏。

AC代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <list>
#include <deque>
#include <queue>
#include <iterator>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <cctype>
#include <ctime>
using namespace std;

typedef long long LL;
const int N=1005;
const double eps=1e-6;
const int M=1<<12;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);

int yinzi(int p)
{
int xh=0;
for(int i=2;i*i<=p;i++)
{
while(p%i==0)
{
xh++;
p/=i;
}
}
if(p>1)
xh++;
return xh;
}

int main()
{
int i,j,T;
int ca=0;
scanf("%d",&T);
while(T--)
{
int a,t=0;
int n,m;
scanf("%d%d",&n,&m);
for(i=0;i<n;i++)
{
int sum=0;
for(j=0;j<m;j++)
{
scanf("%d",&a);
sum+=yinzi(a);//因子不包括1
}
t=t^sum;
}
printf("Case #%d: ",++ca);
if(t==0)
printf("NO\n");
else
printf("YES\n");
}
return 0;
}
/*
5
2 2
2 3
2 3

2 2
4 9
8 5

3 3
2 3 5
3 9 2
8 8 3

3 3
3 4 5
4 5 6
5 6 7

2 3
4 5 6
7 8 9
*/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: