CodeForces 768E Game of Stones 打表找规律
2017-02-22 14:22
411 查看
题意:
在经典Nim博弈的基础上增加了新的限制:如果从这堆石子中移走\(x\)个石子,那么之后就不能再从这堆移走\(x\)个。分析:
因为之前的操作会对后面的转移有影响,所以在保存状态时还要记录哪些数量的石子可以移走。\(d(i,S)\)表示现在有\(i\)个石子,\(S\)中\(1\)的位置表示可以移走对应数量的石子,打表求出\(SG\)函数值。
打表代码:
#include <cstdio> #include <cstring> bool vis[100]; int mex() { for(int i = 0; ; i++) if(!vis[i]) return i; } int sg[11][1 << 10]; int main() { memset(sg, -1, sizeof(sg)); for(int i = 0; i < (1 << 10); i++) sg[0][i] = 0; for(int i = 1; i <= 10; i++) { sg[i][0] = 0; for(int j = 1; j < (1 << 10); j++) { memset(vis, false, sizeof(vis)); for(int k = 0; k < i; k++) if((j >> k) & 1) vis[sg[i - k - 1][j ^ (1 << k)]] = true; sg[i][j] = mex(); } } for(int i = 0; i <= 10; i++) printf("i = %d: sg = %d\n", i, sg[i][(1 << i) - 1]); return 0; }
找到规律后就把问题解决了。
#include <cstdio> int sg[61]; int main() { for(int i = 1, p = 1; p <= 60; i++) { for(int j = 0; j < i + 1 && p <= 60; j++) { sg[p++] = i; } } int ans = 0; int n; scanf("%d", &n); while(n--) { int x; scanf("%d", &x); ans ^= sg[x]; } if(ans) printf("NO\n"); else printf("YES\n"); return 0; }
相关文章推荐
- Codeforces 768E Game of Stones 博弈SG(打表)
- UVA 1482 - Playing With Stones(SG打表规律)
- codeforces 768E Game of Stones
- UVA-1482 Playing With Stones(SG函数打表找规律)
- codeforces 768E Game of Stones
- Codeforces 456B Fedya and Maths 打表找规律
- UVA 1482 - Playing With Stones(SG打表规律)
- Codeforces 768E Game of Stones 博弈
- Codeforces 768E Game of Stones
- HDU 5795 A Simple Nim (SG函数+打表找规律)
- codeforces 553B B. Kyoya and Permutation(找规律)
- Codeforces 707 C. Pythagorean Triples(找规律)——Codeforces Round #368 (Div. 2)
- Codeforces 57C Array dp暴力找到规律
- Codeforces 145A-Lucky Conversion(规律)
- CodeForces - 376C Divisible by Seven(数论:同余定理)(找规律)
- Codeforces 715A & 716C Plus and Square Root【数学规律】 (Codeforces Round #372 (Div. 2))
- hdu_5894_hannnnah_j’s Biological Test(打表找规律)
- Dreamoon and Sets CodeForces - 476D <找规律>
- Codeforces 903A A - Hungry Student Problem 规律
- 【NOIP 模拟赛】中值滤波 打表找规律