题目链接:http://poj.org/problem?id=1067
威佐夫博弈 (Wythoff game): 当两堆石子的数量符合特定关系时,先行者必赢。两堆石子分别有a,b个石子时(a<=b), floor( (b-a) * ( (sqrt(5)+1) /2 ) ) == a 时,先行者必输。代码如下:
1 #include <iostream> 2 #include <math.h> 3 #include <stdio.h> 4 #include <cstdio> 5 #include <algorithm> 6 #include <string.h> 7 #include <string> 8 #include <sstream> 9 #include <cstring> 10 #include <queue> 11 #include <vector> 12 #include <functional> 13 #include <cmath> 14 #include <set> 15 #define SCF(a) scanf("%d", &a) 16 #define IN(a) cin>>a 17 #define FOR(i, a, b) for(int i=a;i<b;i++) 18 #define Infinity 999999999 19 #define NInfinity -999999999 20 #define PI 3.14159265358979323846 21 #define MAXN 1000000005 22 #define RATIO (sqrt(5.0)+1.0)/2.0 23 typedef long long Int; 24 using namespace std; 25 26 int main() 27 { 28 int a, b; 29 while (scanf("%d %d", &a, &b) != EOF) 30 { 31 if (a > b) 32 { 33 int temp = b; 34 b = a; 35 a = temp; 36 } 37 if (floor((b - a) * RATIO) == a) 38 { 39 printf("0\n"); 40 } 41 else 42 printf("1\n"); 43 44 } 45 return 0; 46 }