裸威佐夫博奕。证明见:http://blog.youkuaiyun.com/acm_cxlove/article/details/7854530。
代码如下:
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
using namespace std;
double eps = 1e-9;
int main()
{
#ifdef test
freopen("input.txt", "r", stdin);
#endif
int a, b;
while(scanf("%d%d", &a, &b) != EOF)
{
if(a > b)
swap(a, b);
double k = b - a;
int ans = k * (sqrt(5.0) + 1) / 2.0;
if(ans == a)
puts("0");
else
puts("1");
}
return 0;
}

本文介绍了一种名为裸威佐夫博弈的游戏,并通过算法分析确定了游戏的胜者。该文提供了一个简洁的C++实现代码,利用黄金分割比例来判断玩家是否能赢得比赛。
1295

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



