UVA-1482 Playing With Stones(SG函数打表找规律)

来源:互联网 发布:对冲基金编程 编辑:程序博客网 时间:2024/04/30 06:55

                    Playing With Stones   UVA1482


今天训练博弈的时候看到了这道题,看到1e18的数据很快就把SG函数表打了出来,准备找规律,但是无论怎么找都找不到一个比较好的公式,后来看了别人的博客,发现只要a是奇数,那么SG(a)=SG(a/2),这个规律实在是高明,让这道题直接变成水题,膜拜大佬。

#pragma comment(linker, "/STACK:1024000000,1024000000") #include <iostream>#include <cstdio>#include <cstring>#include <string>#include <cstdlib>#include <cmath>#include <vector>#include <queue>#include <map>#include <algorithm>#include <set>#include <functional>using namespace std;typedef long long LL;typedef unsigned long long ULL;const int INF = 1e9 + 5;const int MAXN = 1000005;const int MOD = 1e9 + 7;const double eps = 1e-8;const double PI = acos(-1.0);LL getSG(LL x){if (x & 1)return getSG(x / 2);return x / 2;}int main(){int T;int n;LL ans;LL x;scanf("%d", &T);while (T--){ans = 0;scanf("%d", &n);while (n--){scanf("%lld", &x);ans ^= getSG(x);}if (ans == 0)printf("NO\n");elseprintf("YES\n");}}