UVA 11859 - Division Game (SG博弈)

题目地址: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
*/


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值