洛谷 P2252 [SHOI2002]取石子游戏|【模板】威佐夫博弈

传送门


解题思路

结论题,威佐夫博弈就是让你背个结论。

若(向下取整)两个数的差*黄金分割比 == 较小的数,则先手输,否则先手胜。

注意先确定两个数的大小,黄金分割比用double。

AC代码

 1 #include<cstdio>
 2 #include<iostream>
 3 #include<cstring>
 4 #include<iomanip>
 5 #include<cmath>
 6 #include<algorithm>
 7 using namespace std;
 8 int n,m;
 9 double a=(sqrt(5.0)+1.0)/2.0;
10 int main(){
11     while(cin>>n>>m){
12         if(n>m) swap(n,m);
13         if(floor((m-n)*a)==n) cout<<0<<endl;
14         else cout<<1<<endl;    
15     }
16     return 0;
17 }

 

posted @ 2021-04-18 17:57  尹昱钦  阅读(49)  评论(0编辑  收藏  举报