UVA-1482 Playing With Stones(SG函数打表找规律)
2017-08-09 09:18
507 查看
Playing With Stones
UVA1482
![](https://img-blog.csdn.net/20170809091417471?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQva2VsZTUyaGU=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
今天训练博弈的时候看到了这道题,看到1e18的数据很快就把SG函数表打了出来,准备找规律,但是无论怎么找都找不到一个比较好的公式,后来看了别人的博客,发现只要a是奇数,那么SG(a)=SG(a/2),这个规律实在是高明,让这道题直接变成水题,膜拜大佬。
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"); } }
相关文章推荐
- UVA 1482 - Playing With Stones(SG打表规律)
- UVA 1482 - Playing With Stones(SG打表规律)
- uva 10515 规律打表
- HDU 5795 A Simple Nim (SG函数+打表找规律)
- UVALive 5116 Dividing Stones(dfs + 打表)
- UVA 10706 Number Sequence (找规律 + 打表 + 查找)
- HDU 3032.Nim or not Nim?【SG函数打表找规律】【4月11】
- LA 5059 (找规律 SG函数) Playing With Stones
- CodeForces 768E Game of Stones 打表找规律
- hdu5795A Simple Nim(SG函数、打表找规律)
- HDU 3032 Nim or not Nim(SG函数打表找规律)
- HDU5795 SG函数(打表然后归纳规律),示例3
- hdu_1517(SG函数+打表找规律)
- HDU 4664 Triangulation (SG函数,打表找规律)
- uva 12716 打表找规律
- uvalive 5059 Playing With Stones(组合游戏,SG函数)@
- HDU 5795 A Simple Nim 打表求SG函数的规律
- UVALive 6844 Combination(打表找规律)
- UVA 10706 Number Sequence (找规律 + 打表 + 查找)
- HDU-5795 A Simple Nim(SG函数打表找规律)