UVA 1482 Playing With Stones

 

(蓝书里有这个题貌似)

一言不合就打表,可以发现sg数组是个分形的,所以可以推出递推式:

1.x是偶数时,sg(x)=x/2

2.否则,sg(x)=sg(x/2)

 

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<cstring>
#define ll long long
using namespace std;
ll sg(ll x){
    return (x&1)?sg(x>>1):x>>1;
}
int T,n;
ll tot,a;
int main(){
    scanf("%d",&T);
    while(T--){
        tot=0;
        scanf("%d",&n);
        while(n--){
            scanf("%lld",&a);
            tot^=sg(a);
        }
        
        if(tot) puts("YES");
        else puts("NO");
    }
    
    return 0;
}

 

相关文章:

  • 2022-12-23
  • 2021-06-10
  • 2021-07-29
  • 2021-11-18
  • 2021-07-15
  • 2021-07-15
  • 2022-02-09
  • 2021-07-26
猜你喜欢
  • 2021-05-29
  • 2022-02-10
  • 2021-08-29
  • 2022-12-23
  • 2021-08-14
  • 2021-12-02
  • 2022-12-23
相关资源
相似解决方案