poj 1067 取石子游戏

取石子游戏
     
     

Description

有 两堆石子,数量任意,可以不同。游戏开始由两个人轮流取石子。游戏规定,每次有两种不同的取法,一是可以在任意的一堆中取走任意多的石子;二是可以在两堆 中同时取走相同数量的石子。最后把石子全部取完者为胜者。现在给出初始的两堆石子的数目,如果轮到你先取,假设双方都采取最好的策略,问最后你是胜者还是 败者。

Input

输入包含若干行,表示若干种石子的初始情况,其中每一行包含两个非负整数a和b,表示两堆石子的数目,a和b都不大于1,000,000,000。

Output

输出对应也有若干行,每行包含一个数字1或0,如果最后你是胜者,则为1,反之,则为0。

Sample Input

2 1
8 4
4 7

Sample Output

0
1
0
 1 #include<iostream>  
 2 #include<string.h>  
 3 #include<stdio.h>  
 4 #include<ctype.h>  
 5 #include<algorithm>  
 6 #include<stack>  
 7 #include<queue>  
 8 #include<set>  
 9 #include<math.h>  
10 #include<vector>  
11 #include<map>  
12 #include<deque>  
13 #include<list>  
14 using namespace std;
15 int main ()
16 {
17     int a, b;
18     int k, c;
19     while ( scanf ( "%d%d", &a, &b ) != EOF )
20     {
21   if (a == 0 && b == 0)
22   {
23    printf("1 ");
24    continue;
25   }
26         if ( a > b )
27         {
28             c = a;
29             a = b;
30             b = c;
31         }
32         k = b - a;
33         c = ( int )( ( ( 1.0 + sqrt ( 5.0 ) ) / 2.0 ) * ( double )k );
34         if ( c == a )
35         {
36             printf ( "0
" );
37         }
38         else
39         {
40             printf ( "1
" );
41         }
42     }
43     return 0;
44 }
View Code
原文地址:https://www.cnblogs.com/qscqesze/p/3877314.html