HDU_1527 取石子游戏(威佐夫博弈)

  威佐夫博弈公式:当处在奇异局势时,ak = (k*(1 + sqrt(5))/2), bk = ak + k;所以,这题套公式即可:

My Code:

#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

int main(){
int n, m, k, tmp;
while(~scanf("%d%d", &n, &m)){
if(m > n){
n = n + m;
m = n - m;
n = n - m;
}
k = n - m;
tmp = (int)(k*(1 + sqrt(5))/2);
if(tmp == m)
putchar('0');
else
putchar('1');
putchar('\n');
}
return 0;
}



你可能感兴趣的:(HDU)