Please indicate the source for reprinting, thank you http://blog.csdn.net/ACM_cxlove?viewmode=contents
Given two numbers, a and b, subtract several multiples of b from the larger number, and if one of the numbers is 0, you will win.
http://acm.hdu.edu.cn/showproblem.php?pid=1525
For two numbers a and b, a situation that will always appear is b, a%b, which is inevitable. If a>=b&&a<2*b, then there is only one situation, directly to b,a%b. Otherwise there are multiple situations.
For the situation of a/b==1, it is only possible to get to b, a%b, and there is no choice. And if a/b>=2, the first mover can choose who faces the situation like b, a%b
Obviously the player is smart enough b, a%b who will win and lose is clear, the first player will win in the situation of a/b>=2
- #include<iostream>
- #include<cstdio>
- #include<cstring>
- #include<algorithm>
- #include<cmath>
- #include<vector>
- #include<string>
- #include<map>
- #define LL long long
- #define N 1000000
- #define inf 1<<20
- usingnamespace std;
- int main(){
- int a,b;
- while(scanf("%d%d",&a,&b)!=EOF&&a+b){
- if(a<b)
- swap(a,b);
- bool stan=true;
- while(1){
- if(b==0||a%b==0||a/b>=2) break;
- int t=a;
- a=b;
- b=t-a;
- apartment =! apartment;
- }
- if(stan)
- printf("Stan wins\n");
- else
- printf("Ollie wins\n");
- }
- return 0;
- }