巴什博奕。
代码如下:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
bool ways[1002];
int vis[10] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512};
int main()
{
#ifdef test
freopen("input.txt", "r", stdin);
#endif
int n;
ways[0] = false;
while(scanf("%d", &n) != EOF)
{
for(int i=1; i<=n; ++i)
{
ways[i] = false;
for(int j=0; j<10; ++j)
if(i>=vis[j] && !ways[i-vis[j]])
{
ways[i] = true;
break;
}
}
if(ways[n])
printf("Kiki\n");
else
printf("Cici\n");
}
return 0;
}

本文介绍了一种解决巴什博奕问题的算法实现。通过使用动态规划思想,该算法可以判断在给定初始石子数量的情况下,先手玩家是否能赢得游戏。代码实现了输入石子数量后,输出胜者的过程。
176

被折叠的 条评论
为什么被折叠?



