codeforces 399 E. Game of Stones 博弈 思维题
来源:互联网 发布:计算机二级vb视频教程 编辑:程序博客网 时间:2024/06/05 16:55
题目地址
http://codeforces.com/contest/768/problem/E
题意
有
思路
官方题解的思路是计算每个s值对应的sg函数,因为s值只有60种不同的情况,所以计算量不是很大。但是现在看到的很多代码都是把
看了看cf题解下的讨论,大致的证明思路是这样的:一堆石子不能取重复的石子数,那么这堆石子最多可以被取x次,因为可以把这堆石子分成x份,每份的个数分别为1, 2, …, x - 1, x个,一次操作就是从这些石子中任取几份。这样题目就退化成了一般的nim博弈:一堆石子有x个,每次取不为0任意的石子数,不能取的一方判输。
然后统计所有的石子堆的异或和就好了。
遇到博弈题,的确应该一步步从sg值出发来考虑问题。
代码
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;int sg[70];int n;int main() { int now = 1, tot = 1, nxt = 2; for (; tot <= 60; ++nxt) { while (tot <= 60 && now + nxt > tot) sg[tot++] = nxt - 1; now += nxt; }// for (int i = 0; i <= 60; ++i) cout<<i<<": "<<sg[i]<<endl; while (~scanf("%d", &n)) { int ans = 0; int x; for (int i = 0; i < n; ++i) { scanf("%d", &x); ans ^= sg[x]; } if (ans) puts("NO"); else puts("YES"); }}
1 0
- codeforces 399 E. Game of Stones 博弈 思维题
- Codeforces 768E Game of Stones 博弈
- Codeforces Round #399 E Game of Stones 博弈
- codeforces 768 E Game of Stones(博弈)
- Codeforces 768E Game of Stones 博弈SG(打表)
- CodeForces 768E Game of Stones (Nim博弈)
- Codeforces Round #399:E. Game of Stones
- Codeforces 768E Game of Stones
- codeforces 786E Game of Stones
- 768E Game of Stones[Nim游戏][博弈]
- Game of Taking Stones (hdu5973)——2016大连现场赛C题 威佐夫博弈
- HDU 5973 Game of Taking Stones 博弈+高精度
- ZOJ 3964 Yet Another Game of Stones (博弈)
- Game of Taking Stones (大数 + 威佐夫博弈 java写的)
- HDU5973 Game of Taking Stones (大数博弈)
- ZOJ 3964 Yet Another Game of Stones (博弈)
- ZOj 3964Yet Another Game of Stones(nim博弈)
- HDU 5973Game of Taking Stones 51nod 1185 威佐夫游戏 V2(威佐夫博弈)
- 455. Assign Cookies
- POJ 2411 Mondriaan's Dream [状压DP做法]
- HDOJ 1005 Java 答案
- 深度学习caffe实战(一)验证码识别
- python解析基于xml格式的日志文件
- codeforces 399 E. Game of Stones 博弈 思维题
- javascript Object.is 与 === 的区别
- 昇润科技将在三月底推出CC2640R2 SDK开发平台
- 可以设置宽高比,宽度确定,高度比例缩放的ImageView快速实现
- JVM调优总结(十)-调优方法
- 基于kubernetes和SpringCloud微服务构建方案
- ios 判断app程序第一次启动方法
- JAVA从入门到精通(4)
- 在Express的页面模板中的变量的定义与使用总结