POJ2348+博弈
1 /* 2 博弈 3 关键态:较大数是较小数的2倍以上。 4 */ 5 #include<stdio.h> 6 #include<string.h> 7 #include<stdlib.h> 8 #include<algorithm> 9 #include<iostream> 10 #include<queue> 11 #include<map> 12 #include<stack> 13 #include<set> 14 #include<math.h> 15 using namespace std; 16 typedef long long int64; 17 //typedef __int64 int64; 18 typedef pair<int64,int64> PII; 19 #define MP(a,b) make_pair((a),(b)) 20 const int maxn = 1005; 21 const int inf = 0x7fffffff; 22 const double pi=acos(-1.0); 23 const double eps = 1e-8; 24 25 int Record[ maxn ]; 26 27 int main(){ 28 int n,m; 29 //freopen("in.txt","r",stdin); 30 //freopen("out.txt","w",stdout); 31 while( scanf("%d%d",&n,&m)==2,n+m ){ 32 if( n<m ) swap( n,m ); 33 if( n%m==0 ){ 34 puts("Stan wins"); 35 continue; 36 } 37 int cnt = 0; 38 int r; 39 while( 1 ){ 40 r = n%m; 41 Record[ cnt++ ] = n/m; 42 n = max( m,r ); 43 m = min( m,r ); 44 if( r==0 ) break; 45 } 46 int f; 47 for( f=0;f<cnt;f++ ){ 48 if( Record[f]>1 ){ 49 break; 50 } 51 } 52 if( f==cnt ){ 53 if( f%2==1 ) puts("Stan wins"); 54 else puts("Ollie wins");//没有达到关键态 55 } 56 else{ 57 if( f%2==1 ) puts("Ollie wins"); 58 else puts("Stan wins"); 59 //表示达到了关键态,即较大数是较小数的2倍以上。 60 } 61 } 62 return 0; 63 } 64 65 66
keep moving...