Take a stone game
Time Limit: 1000MS |
|
Memory Limit: 10000K |
Total Submissions: 35727 |
|
Accepted: 12065 |
Description
There are two piles of stones, the quantity is arbitrary, can be different. The game began with two people taking turns to take stones. The game rules, each time there are two different ways, one can take away any number of stones in any heap, and two can take the same number of stones in both piles. Finally, the stones are all taken out as the winner. Now give the number of the initial two piles of stones, if it's your turn to take it first, assume that both sides adopt the best strategy and ask whether you are the winner or the loser.
Input
The input contains several lines that represent the initial condition of several kinds of stones, each of which contains two nonnegative integers a and B, indicating the number of stones, A and B, not greater than 1,000,000,000.
Output
The output corresponds to a number of lines, each containing a number 1 or 0, or 1 if you are the winner, or 0 for the other.
Sample Input
2 18 44 7
Sample Output
010
Reprint Please declare: http://blog.csdn.net/lionel_d
The typical Witzov game model, although it feels difficult to look like, but with the introduction of other people's formula, it becomes very simple
Previous blog: http://www.cnblogs.com/celia01/archive/2011/11/15/2250171.html
Inside the game model is quite full.
Code:
#include <stdio.h> #include <math.h>int main () {double p = (sqrt (5.0) +1)/2; int A, B; while (~SCANF ("%d%d", & (a,&b)) {if (a>b) {int temp = A;a = B;b = temp;} int j = b-a; if (a = = (int) (j*p)) {puts ("0");} Else{puts ("1");}} return 0;}
hdu1527 & poj1067 take Stone Games Witzov game model, template title O (╯-╰) o