HDU 2177 Witzov Game Distortion

Source: Internet
Author: User

Take (2 piles) Stone game

Time limit:3000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 1587 Accepted Submission (s): 962


Problem description has two piles of stones, which can be different in quantity. The game began with two people taking turns to take stones. The game rules, each time there are two different ways, one can take away any number of stones in any heap, and two can take the same number of stones in both piles. Finally, the stones are all taken out as the winner. Now give the number of the initial two piles of stones, if it's your turn to take it first, assume that both sides adopt the best strategy and ask whether you are the winner or the loser. If you win, how do you take your son for the 1th time?

Input inputs contain several lines that represent the initial condition of several stones, where each row contains two nonnegative integers a and B, indicating the number of stones, A and b are not greater than 1,000,000, and a<=b. A=b=0 exit.

Output outputs also have several lines, if you are the loser, then 0, conversely, the output 1, and the output you win the 1th time after you take the stone the remaining two piles of stone x,y,x<=y. If you take a stone in any heap, you can win the same number of stones simultaneously in both piles, and output the same number of stones first.

Sample INPUT1 2 5 84 72 20 0

Sample Output014 73 5010 01 2

Authorzhousc

Source ecjtu Summer Contest

Recommendlcy | We have carefully selected several similar problems for you:2176 2180 1536 1850 1729 front of the judgment is set template, Witzov principle understand, set template naturally easy, the following loss Into the procedure of the process of violence can be, detailed details of the violence I have commented on the back of the weak explosion-----> Final preparation before the game
#include <stdio.h>#include<string.h>#include<math.h>intA, B;intMain () {Doublex = (1+ sqrt (5.0))/2.0;//Matrix Golden Segment number    inti,k,temp,n,m;  while(SCANF ("%d%d", &a,&b)!=eof&& (A +b)) {if(a>b) {temp=A; A=b; b=temp; } k=b-A; if((int) (k*x) ==a)//Judging whether it is a singular state,printf"%d\n",0);//if it is singular state, then the first person will be defeated        Else{printf ("%d\n",1);  for(i=1; i<=a;i++)//a situation in which violence is taken from two piles.{n=a-i; M=b-i; K=m-O; if((int) (k*x) = =N) printf ("%d%d\n", n,m);//without exiting the loop, depending on the nature of the singular state, there will only be one            }             for(i=b-1; i>=0; i--)//in the case of violence taken from one,//one of the things to note here is that you need to take from a lot of that pile, so count the numbers from high to low .{n=A; M=i; if(n>m) {temp=N; N=m; M=temp; } k=m-N; if((int) (k*x) = =N) printf ("%d%d\n", n,m); }        }    }    return 0;}

HDU 2177 Witzov Game Distortion

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.