每天一道博弈论之“威佐夫博弈”   题意:   题解:

  给你两堆石子,有两种操作:1,在某一堆取x个(x>=1个);2,在两堆同时取x个(x>=1)。

    给你初始两堆石子数,问先手胜还是后手胜。

  题解:

  其实这是著名的威佐夫博弈,有个结论是假设两堆石子为(a,b)(a<=b),那么如果满足{a == floor(0.5*(sqrt(5)+1)*(b-a)},那么后手胜,否则先手胜。

http://poj.org/problem?id=1067

  代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define LL long long
#define RI register int
using namespace std;
const int INF = 0x7ffffff ;

int main() {
    int a, b ;
    while(scanf("%d %d",&a,&b)!=EOF) {
        if(a > b) swap(a,b) ;
        if(a == floor(((sqrt(5.0)+1)*0.5)*(b-a))) printf("0
") ;
        else printf("1
") ;
    }
    return 0 ; 
}
View Code

另:一定是while(scanf()!=EOF)而不是while(scanf())