HDU 2177 (2 heap) Stone game
Rock game (2 heaps)
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission (s): 1008 Accepted Submission (s): 606
Problem Description has two piles of stones, which can be any number and can be different. The game started with taking stones in turn by two people. The game stipulates that there are two different methods to get each time. One is to remove any number of stones from any pile; the other is to take the same number of stones from both piles. Finally, the winner of all the stones. Now we will give you the initial number of two stones. If it is your turn to take them first, let us assume that both Parties adopt the best strategy and ask whether you are the winner or the loser at last. If you win, how do you get a child for 1st times?
The Input contains several rows, indicating the initial conditions of several stones. Each row contains two non-negative integers a and B, indicating the number of two stones. Neither a nor B is greater than 1,000,000, and a <= B. A = B = 0 exit.
The Output also has several rows. If you are the loser at last, the Output value is 0. Otherwise, the Output value is 1, and output the number of the remaining two piles of stones x, y, x <= y after you win 1st times. If you take the same number of stones away from any pile, you can win the same number of stones at the same time in both piles. First, you can output the situation of taking the same number of stones away.
Sample Input
1 2 5 84 72 20 0
Sample Output
014 73 5010 01 2
Vitov Boyi !!!
However, you need to enter the best stone for the first time !!!!!
The data is not big, and the brute force enumeration is decisive !!!
The AC code is as follows:
#include
#include#include
#include
using namespace std;int main(){ int n,m; double gs=(sqrt(5.0)+1)/2.0; while(~scanf("%d%d",&n,&m)&&(n||m)) { if(n
=0;i--) { if((int)(abs(a-i)*gs)==min(n-i,m)) {printf("%d %d\n",min(n-i,m),max(n-i,m));break;} } } return 0;}