UVaLive5059 Playing With Stones

数学问题 博弈 SG函数

我总觉得这题做过的……然而并没有记录

看上去是一个nim游戏的模型。

手推/打表找一下前几项的规律,发现x是偶数时,sg[x]=x/2,x是奇数时,sg[x]=sg[x div 2]

差点看漏了数据范围是1e18

 1 /*by SilverN*/
 2 #include<algorithm>
 3 #include<iostream>
 4 #include<cstring>
 5 #include<cstdio>
 6 #include<cmath>
 7 #include<vector>
 8 #define LL long long
 9 using namespace std;
10 const int mxn=100010;
11 LL read(){
12     LL x=0,f=1;char ch=getchar();
13     while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
14     while(ch>='0' && ch<='9'){x=x*10+ch-'0';ch=getchar();}
15     return x*f;
16 }
17 int n;
18 LL SG(LL x){
19     if(x%2==0)return x/2;
20     else return SG(x/2);
21 }
22 int main(){
23     int i,j;LL x;
24     int T=read();
25     while(T--){
26         LL res=0;
27         n=read();
28         for(i=1;i<=n;i++){
29             x=read();
30             res^=SG(x);
31         }
32         if(res)printf("YES\n");
33         else printf("NO\n");
34     }
35     return 0;
36 }

 

posted @ 2017-03-21 08:11  SilverNebula  阅读(144)  评论(0编辑  收藏  举报
AmazingCounters.com