洛谷$P$2252 取石子游戏 博弈论

正解:博弈论

解题报告:

传送门!

威佐夫博弈板子昂$QwQ$

关于这一类问题也有个结论,是说,先手必败的状态一定形如$(\left \lfloor i+\phi \right \rfloor,\left \lfloor i+\phi^{2} \right \rfloor)$,然后$\phi=\frac{\sqrt{5}+1}{2}$

证是不会证的了,但找到了一篇证明看这个趴$QAQ$

#include<bits/stdc++.h>
using namespace std;
#define il inline
#define gc getchar()
#define ri register int
#define rb register bool
#define rc register char
#define rp(i,x,y) for(ri i=x;i<=y;++i)

const double phi=(sqrt(5)+1)/2;

il int read()
{
    rc ch=gc;ri x=0;rb y=1;
    while(ch!='-' && (ch>'9' || ch<'0'))ch=gc;
    if(ch=='-')ch=gc,y=0;
    while(ch>='0' && ch<='9')x=(x<<1)+(x<<3)+(ch^'0'),ch=gc;
    return y?x:-x;
}
int main()
{
    ri a=read(),b=read();if(a>b)swap(a,b);ri tmp=(b-a)*phi;
    if(tmp==a)printf("0\n");else printf("1\n");
    return 0;
}
View Code

猜你喜欢

转载自www.cnblogs.com/lqsukida/p/10846729.html