题目大意:两人博弈,给出两个数a和b,较大数减去较小数的任意倍数,结果不能小于0,将两个数任意一个数减到0的为胜者。
思路:设a大于b,分三种情况:
1)a%b = 0:若Stan 先开始,则Stan胜。
2)b<a<2*b:走下一步,递归。
3)a>=2*b:Stan可以通过选择来使自己胜。因为只有两种结果,且输赢一定交替出现,所以出现两种含两种以上的选择的时候此时能够作出“赢”的选择。
思路:设a大于b,分三种情况:
1)a%b = 0:若Stan 先开始,则Stan胜。
2)b<a<2*b:走下一步,递归。
3)a>=2*b:Stan可以通过选择来使自己胜。因为只有两种结果,且输赢一定交替出现,所以出现两种含两种以上的选择的时候此时能够作出“赢”的选择。
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
int stan;
void play(int a,int b)
{
if (a<b)
swap(a,b);
if (a/b>=2 ||a%b==0)
return ;
stan=1-stan;
play(a-b,b);
}
int main()
{
int a,b;
while(cin>>a>>b)
{
if (a==0 && b==0)
break;
stan=1;
play(a,b);
if (stan)
cout<<"Stan wins"<<endl;
else cout<<"Ollie wins"<<endl;
}
return 0;
}