分析博弈类的题的第一步,找必胜态和必败态,这就涉及情况的分类,分类好的话,就容易找到规律。
先找容易判断出来的,或者没有其他选择机会的。
本题中,假设a>b;
(1)a - b
(2)a-b>=b,a-b=b是必胜态,重点是a-b>b的情况,这么想:
假设a=k*b+r 0
#include#include #include using namespace std; void change(int &a,int &b) { int t=a; a=b; b=t; } int test(int a,int b) { int cnt=1; while(a%b) { a-=b; cnt++; if(a b)break; } return cnt%2; } int main() { int a,b,flag; while(scanf(%d%d,&a,&b)!=EOF && a+b) { if(a =b){printf(Stan wins );continue;} if(test(a,b)) printf(Stan wins ); else printf(Ollie wins ); } return 0; }