HDU 2177--Witzov Game

Source: Internet
Author: User

Topic:

Description

There are two piles of stones, the quantity is arbitrary, can be different. 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

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

Output

The output also has several lines, if you are the loser at the end, then 0, the opposite, the output 1, and the output you win the 1th time you take the stone after 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 Input

1 25 84 72 20 0

Sample Output

014 73 5010 01 2 test instructions: As above analysis: Witzov game advanced, mainly when judged to win the situation, judge (A, B) size, and then according to this from the N state->p state, the output after the remaining number of stones.
1#include <cstdio>2#include <cmath>3 intMain ()4 {5     inta,b,k;6     DoubleEps= (1+SQRT (5.0))/2.0;7      while(SCANF ("%d%d", &a,&b) = =2&& (a| |b))8     {9         intT;Ten         if(a>b) One         { At=A; -A=b; -b=T; the         } -k=b-A; -         if(int(k*eps) = =a) -printf"0\n"); +         Else -         { +printf"1\n"); A              for(intI=1; i<=a;i++) at             { -                 intn,m; -n=a-i; -m=b-i; -                 if(n>m) -                 { int=N; -n=m; tom=T; +                 } -k=m-N; the                 if(int(k*eps) = =N) *printf"%d%d\n", n,m); $             }Panax Notoginseng              for(inti=b-1; i>=0; i--) -             { the                 intn,m; +n=A; Am=i; the                 if(n>m) +                 { -t=N; $n=m; $m=T; -                 } -k=m-N; the                 if(int(k*eps) = =N) -printf"%d%d\n", n,m);Wuyi             } the         } -     } Wu     return 0; -}
View Code

HDU 2177--Witzov Game

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.