您的位置:首页 > 其它

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

2017-08-09 09:18 507 查看
                    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");
else
printf("YES\n");
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: