博弈问题,代码量很少的呢,不过题目中间的思想才是重点的。
#include<stdio.h>
int count;
void match(int a,int b)
{ int swap;
if(a<b){ swap=a;
a=b;
b=swap;
}
if(a==b) return; //如果两组数相等,那么面对这个局势的人获胜
if(a/b>=2) return; //如果面对此局势,是必胜的,代码后有注解
else {count++;
match(a-b,b);
}
}
int main()
{ int a,b;
while(scanf("%d%d",&a,&b)!=EOF)
{ if(a==0&&b==0)
return 0;
count=0; //这个是定义了如果每个人都采用PREFECT的战略的话,到达这个必胜的局面时经过的轮数
match(a,b);
//printf("count==%d\n",count);
if(count%2) //如果是奇数轮的话那么后拿的那个人获胜
printf("Ollie wins\n");
else
printf("Stan wins\n");
}
return 0;
}