1. 程式人生 > >POJ 1067 取石子遊戲

POJ 1067 取石子遊戲

main pan ios cnblogs printf can 鏈接 names code

題目鏈接: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 }

POJ 1067 取石子遊戲