【洛谷P2252】取石子游戏

题面

题解

威佐夫博弈

代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include<cstdio>
#include<algorithm>
#include<cmath>
#define RG register

const double Phi((sqrt(5) + 1.) / 2.);
int a, b;
inline int abs(int a) { return a < 0 ? a : -a; }

int main()
{
while(~scanf("%d%d", &a, &b))
{
if(a > b) std::swap(a, b);
int c = abs(a - b) * Phi;
if(c == a) puts("0");
else puts("1");
}
return 0;
}
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×