本文主要是介绍POJ 1067 取石子游戏 威佐夫博弈,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 42314 | Accepted: 14336 |
Description
Input
Output
Sample Input
2 1 8 4 4 7
Sample Output
0 1 0
Source
威佐夫博弈(Wythoff Game):
有两堆各若干的物品,两人轮流从其中一堆取至少一件物品,至多不限,或从两堆中同时取相同件物品,规定最后取完者胜利。
若两堆物品的初始值为(x,y),且x<y,则另z=y-x;
记w=(int)[((sqrt(5)+1)/2)*z ];
若w=x,则先手必败,否则先手必胜。
原文:http://blog.csdn.net/ac_gibson/article/details/41624623
#include <cstdio>
#include <iostream>
#include <string.h>
#include <string>
#include <map>
#include <queue>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <bitset>
#define mem0(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,0x3f,sizeof(a))
using namespace std;
typedef long long ll;
typedef long double ld;
const int inf=0x3f3f3f3f;
const ll llinf=0x3f3f3f3f3f3f3f3f;
const ld pi=acos(-1.0L); int main() {int a,b,c;while (scanf("%d%d",&a,&b)!=EOF) {if (a>b) {c=a;a=b;b=c;}if (floor((b-a)*(sqrt(5.0)+1.0)/2.0)==a) printf("0\n"); else printf("1\n"); }return 0;
}
这篇关于POJ 1067 取石子游戏 威佐夫博弈的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!