Stone game (hangdian 1527)

Source: Internet
Author: User
Stone game Time 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, 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.
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. both A and B are not greater than 1,000,000,000.
The output also has several rows. Each row contains a number 1 or 0. If you are the winner at the end, it is 1. Otherwise, it is 0.
Sample Input
2 18 44 7
 
Sample output
010
// The explanation is displayed on the Internet. /* this is the so-called weizov game in the weizov game. It is a common combination game in ACM. Generally, there are two piles of stones, consider that there are 10 in one pile and 15 in the other. The two sides take turns to take some stones. There are two legal methods: 1. Remove any number of stones from a pile of stones. 2. Remove any of the same number of stones from the pile of stones. The winner of the last stone is agreed to win. The status of the two piles of stones is the same. We use the remaining number of stones (a, B) to represent the State and draw it in the Cartesian coordinate system of the plane. Similar to the above, (0, 0) must be in the P state, which is also called a mandatory defeat state. (0, K), (K, 0), and (k, k) series nodes are definitely not in the P state, but in the winning state. You will certainly win in the face of such a situation, you only need to perform the operation once according to the rules. Then, let's look at the undrawn lattice points above y = x. (1, 2) is the P state. When K is greater than 2, (1, k) is not P. For example, if you face (), you may win. Similarly, (k, 2), (1 + k, 2 + k) are not P states, and these points and their symmetry points are crossed, then find the remaining point above y = x, and you will find that (3, 5) is a P state, so if we only find the P state of a ≤ B, then they are )...... What are their patterns? Ignore (0, 0), and soon you will find that for a in the p-state of I, A = I * (SQRT (5) + 1)/2 and then take the integer; B = a + I. It is related to the Golden split point. The first few failures are as follows )...... It can be found that for the K mandatory point (M (K), n (k), m (k) is the minimum natural number that has not been seen before, n (k) = m (k) + K. The formula used to determine whether a point is a must-have point is related to the Golden Division (I cannot give a strict mathematical proof, but I can tell anyone who can give a strict mathematical proof). 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", & 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 ;}


Stone game (hangdian 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.