To Pebble Games (Hangzhou electric 1527)

Source: Internet
Author: User

Game with PebblesTime limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 3754 Accepted Submission (s): 1890


Problem description has two piles of stones, at random. can be different. The game starts with two people taking the stones in turn. The game rules that there are two different ways to do it each time. One is to be able to take away more random stones in a random pile, and two to take the same amount of stones at the same time in both piles.

Finally, all the stones were taken as winners. Now give the number of the initial two piles of stones, if it's your turn to take them first. If both sides take the best strategy. Ask whether you are the winner or the loser in the end.
Input inputs include several lines that represent the initial condition of several kinds of stones, each of which consists of two nonnegative integers a and B. Indicates the number of stones, A and b are not greater than 1,000,000,000.
The output outputs also have several rows, each containing a number of 1 or 0, assuming that you are the winner at the end, or 1, or 0 instead.
Sample Input

2 18 44 7

Sample Output
010
The commentary is on-line to see, to keep the mutual encouragement.//This is Witzov game, the so-called Witzov game, is one of the common combination games in ACM, which is basically this: there are two piles of stones, it is best to think of a pile of 10, there is a pile of 15. The two took turns to take some stones. The legal way has the following two kinds: 1, takes the random many in a heap of stones, 2, takes the same many random stars in two piles of stones. Agreed to take the last stone of the man-made winner, to win the strategy. The two piles of stone status are the same, we use the remaining stone number (a, a, b) to represent the State, and drawn in a plane Cartesian coordinate system.

Similar to the front, (0,0) must be P-state, also known as the failure state. (0,k), (k,0), (k,k) series of nodes is certainly not P-state. But to win the state, you face this situation will certainly win, just to follow the rules to take once you can. Then see y = the lattice point that is not crossed above X, which is P-state.

K > 2 o'clock, (1,k) is not P-state. For example, if you face the 1,3 situation, you are likely to win. Similarly, (k,2), (1 + k, 2 + K) are also not P-states, and these points are zoned out and their symmetry points. Then find the remaining points above y = x, and you will find that (3,5) is a P-state, so go on, assuming we just find out the P-state of A≤b. Then they are (0,0). (For each). (3,5), (4,7), (6,10) ... Do they have any rules? Ignoring (0,0), it is very fast to find a for the P-State of I. A = i * (sqrt (5) + 1)/2 then rounding. and B = A + I. Had a relationship with the gold cutting point. Some of the previous defeats are as follows: (0,0), (3,5), (4,7), (6,10), (8,13) ... It can be found that M (k) is the smallest natural number that has not been preceded, and N (k) =m (k) +k for the K-Fail Point (M (k), N (k)). Infer that a point is not a must-fail formula related to gold cutting (I cannot give a strict mathematical proof, who can give a strict mathematical proof to remember to tell me), for: M (k) = k * (1 + sqrt (5))/2n (k) = m (k) + K. */#include <stdio.h> #include <math.h>int main () {int m,n,t; while (~SCANF ("%d%d", &m,&n)) {Double A; if (m<n) {t=m; M=n; n=t; } int k=m-n; if (N==int (k* (1+SQRT (5)/2.0)) printf ("0\n"); else printf ("1\n"); } return 0;}



Copyright notice: This article Bo Master original articles, blogs, without consent may not be reproduced.

To Pebble Games (Hangzhou electric 1527)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.