Rock game (hangdian 2177)

Source: Internet
Author: User
Rock game (2 heaps) Time Limit: 3000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 1175 accepted submission (s): 706


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
/* This question is still the vezov game. Take advantage of the important nature: Any natural number is contained in one and only one singular situation. A singular situation is a point of defeat. To understand the weizov game, you can go to the Baidu Library to get started with the game. * // * core idea: use M [K], N [k] is the boundary for analysis. There are three cases (1) If a> M [K], B> N [K], the natural remaining stones are a [k] and B [K]. (2) If a <m [k] (B <n [k]), then you need to find out whether M [I], B [I], and a are available before M [K, is M [I] or N [I] equal to B? Of course, some situations do not need to be considered because they are impossible. (3) If a = m [K], you will be suspended. */# Include <stdio. h> # include <math. h> int A [1000010]; int B [1000010]; int main () {int m, n, T, K, I; A [0] = 0, B [0] = 0; A [1] = 2, B [1] = 1; for (I = 2; I <1000010; I ++) // create a table first. {B [I] = I * (1 + SQRT (5)/2; A [I] = B [I] + I ;} while (scanf ("% d", & M, & N )! = EOF & (m + n) {If (M <n); {T = m; M = N; n = T;} k = m-N; if (n = B [k]) {printf ("0 \ n"); continue;} else // code of the core idea. {Printf ("1 \ n"); If (n <B [k]) {for (I = 1; I <n; I ++) {If (n = B [I] & M> A [I]) printf ("% d \ n", B [I], A [I]); If (M = A [I] & n> B [I]) printf ("% d \ n", B [I], A [I]) ;}}if (n> B [k]) {printf ("% d \ n", B [K], a [k]); for (I = 1; I <n; I ++) {If (n = A [I] & M> B [I]) printf ("% d \ n", B [I], a [I]); If (n = B [I] & M> A [I]) printf ("% d \ n", B [I], a [I]) ;}}} return 0 ;}


Rock game (hangdian 2177)

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.