GYM 100090 H.Game with the Stones(博弈论)
2017-03-07 18:43
1016 查看
^%Description
n堆石子,每次要把所有数量不小于2的堆分成两个非空堆,谁不能分谁输,Constantine
和Mike轮流分,Constantine先手,双方均采取最佳策略,问谁必胜
Input
第一行一整数n表示石子堆数,之后n个整数a[i]表示每堆石子数量(1<=n<=100,1<=a[i]<=1e9)
Output
输出谁必胜
Sample Input
4
2 4 6 8
Sample Output
Constantine
Solution
显然结果只与石子数最多的一堆有关,对于最大堆x,其后继状态只有(x+1)/2,….,x这(x+1)/2个状态,如果这些状态全部必胜则当前状态必败,否则当前状态必胜,反过来看,一个必败状态y能够影响的最大状态是2*y,也就是说如果y是必败态,则y+1,y+2,…,2*y都是必胜态,2*y+1是必败态,而1是必败态,所以从1开始推可知所有2^m-1都是必败态,其他都是必胜态
Code
n堆石子,每次要把所有数量不小于2的堆分成两个非空堆,谁不能分谁输,Constantine
和Mike轮流分,Constantine先手,双方均采取最佳策略,问谁必胜
Input
第一行一整数n表示石子堆数,之后n个整数a[i]表示每堆石子数量(1<=n<=100,1<=a[i]<=1e9)
Output
输出谁必胜
Sample Input
4
2 4 6 8
Sample Output
Constantine
Solution
显然结果只与石子数最多的一堆有关,对于最大堆x,其后继状态只有(x+1)/2,….,x这(x+1)/2个状态,如果这些状态全部必胜则当前状态必败,否则当前状态必胜,反过来看,一个必败状态y能够影响的最大状态是2*y,也就是说如果y是必败态,则y+1,y+2,…,2*y都是必胜态,2*y+1是必败态,而1是必败态,所以从1开始推可知所有2^m-1都是必败态,其他都是必胜态
Code
#include<cstdio> #include<iostream> #include<cstring> #include<algorithm> #include<cmath> #include<vector> #include<queue> #include<map> #include<set> #include<ctime> using namespace std; typedef long long ll; #define INF 0x3f3f3f3f #define maxn 1111 int main() { int n; while(~scanf("%d",&n)) { int a,ans=0; while(n--) { scanf("%d",&a); ans=max(ans,a); } ans++; int gg=1; while(ans) { if(ans<=2)break; if(ans&1)gg=0; ans/=2; } printf("%s\n",gg==0?"Constantine":"Mike"); } }
相关文章推荐
- Problem H. Game with the Stones 博弈论
- GYM 101147 A.The game of Osho(博弈论)
- 【博弈论】【SG函数】【找规律】Gym - 101147A - The game of Osho
- poj 2996 Help Me with the Game
- POJ-2996-Help Me with the Game
- Help Me with the Game
- Create a Brick Breaker Game with the Corona SDK: Collision Detection
- poj-2996&2993 Help Me with the Game
- POJ 2996 Help Me with the Game(模拟)
- poj 2996 Help Me with the Game
- gym 101158J - Cover the Polygon with Your Disk [模拟退火+多边形与圆面积交]
- Create a Brick Breaker Game with the Corona SDK: Game Controls
- [博弈论] cf317 D Game with Powers
- POJ 2996 Help Me with the Game(模拟)
- C++ Qt Game Tutorial 2 - Moving With the Arrow Keys
- poj 2996 Help Me with the Game(模拟)
- 湖大暑假训练赛2:The Stones Game
- poj 2996 Help Me with the Game
- POJ-2996-Help Me with the Game
- poj 2996 Help Me with the Game