nyoj 161 Retrieving stones (four) (Wyzhov game)

Take stones (4)

Time Limit: 1000  ms | Memory Limit: 65535  KB
Difficulty: 4
describe
There are two piles of stones, the number of which can be different. The game begins with two people taking turns taking stones. The game stipulates that there are two different ways to take each time. One is to take as many stones as you want from any pile; the other is to take the same number of stones from two piles at the same time. In the end, the one who removes all the stones is the winner. Now given the initial number of two piles of stones, if it is your turn to take first, assuming both sides take the best strategy, ask whether you are the winner or the loser in the end.
enter
The input contains several lines, representing the initial conditions of several kinds of stones, each line contains two non-negative integers a and b, representing the number of two piles of stones, a and b are not greater than 1,000,000,000.
output
The output also has several lines, each line contains a number 1 or 0, if you are the winner in the end, it is 1, otherwise, it is 0.
sample input
2 1
8 4
4 7
Sample output
0
1
0


Conclusion: if ( nm)*(sqrt(5.0)+1.0)/2.0! =m , the first player wins, otherwise it loses.


#include<stdio.h>
#include<algorithm>
#include<math.h>
using namespace std;
intmain()
{
	int n,m;
	while(~scanf("%d%d",&n,&m))
	{
		if(n<m) swap(n,m);
		if(floor((n-m)*(sqrt(5.0)+1.0)/2)!=m)
		printf("1\n");
		else printf("0\n");
	}
}

Guess you like

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