UVA 11859 - Division Game (SG博弈)

来源:互联网 发布:自己能干淘宝秒杀群吗 编辑:程序博客网 时间:2024/06/05 04:05

题目地址: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;}/*52 22 32 32 24 98 53 32 3 53 9 28 8 33 33 4 54 5 65 6 72 34 5 67 8 9*/


原创粉丝点击