HDU 1525 Euclid's Game

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

[cpp]  view plain  copy
  1. #include<iostream>  
  2. #include<cstdio>  
  3. #include<cstring>  
  4. #include<algorithm>  
  5. #include<cmath>  
  6. #include<vector>  
  7. #include<string>  
  8. #include<map>  
  9. #define LL long long  
  10. #define N 1000000  
  11. #define inf 1<<20  
  12. usingnamespace std;   
  13. int  main(){  
  14.     int a,b;  
  15.     while(scanf("%d%d",&a,&b)!=EOF&&a+b){  
  16.         if(a<b)  
  17.             swap(a,b);  
  18.         bool stan=true;  
  19.         while(1){             
  20.             if(b==0||a%b==0||a/b>=2) break;  
  21.             int t=a;  
  22.             a=b;  
  23.             b=t-a;  
  24.             apartment =! apartment;  
  25.         }  
  26.         if(stan)  
  27.             printf("Stan wins\n");  
  28.         else  
  29.             printf("Ollie wins\n");  
  30.     }  
  31.     return 0;  
  32. }  
  33.       

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325764510&siteId=291194637