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 }

 

转载于:https://www.cnblogs.com/SilverNebula/p/6592623.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值