HDU 1525 Euclid's Game 找规律博弈

转载请注明出处,谢谢 http://blog.csdn.net/ACM_cxlove?viewmode=contents           

给出两个数,a和b,将大的数中,减去若干b的倍数,最终有一个数为0的话就胜了。

http://acm.hdu.edu.cn/showproblem.php?pid=1525

两个数a和b,总会出现的一个局面是b,a%b,这是必然的,如果a>=b&&a<2*b,那么只有一种情况,直接到b,a%b。否则有多种情况。

对于对于a/b==1这种局面,只可能到b,a%b,没有选择。而a/b>=2的话,先手可以选择由谁面对b,a%b这样的局势

显然选手足够聪明b,a%b谁必胜必败已经清楚,先手在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. using namespace 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.             stan=!stan;  
  25.         }  
  26.         if(stan)  
  27.             printf("Stan wins\n");  
  28.         else  
  29.             printf("Ollie wins\n");  
  30.     }  
  31.     return 0;  
  32. }  
  33.       

猜你喜欢

转载自blog.csdn.net/yxpandjay/article/details/77987094