Take (2 piles) Stone game
Time limit:3000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 2054 Accepted Submission (s): 1238
problem DescriptionThere 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?
InputThe 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.
OutputThe 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 2 5 84 72 20 0
Sample Output
014 73 5010) 01 2
AuthorZHOUSC
Sourceecjtu Summer Contest
Test instructions: Chinese question ..... Don't talk ...
Analysis: The problem is the basic problem, but to understand the specific how to take, do not understand the words .... As for violence, this data is not very well .....
#include <iostream> #include <cstdio> #include <cstring> #include <stack> #include <queue > #include <map> #include <set> #include <vector> #include <cmath> #include <algorithm> Using namespace Std;const double eps = 1e-6;const double pi = ACOs ( -1.0); const int INF = 1e9;const int MOD = 1e9+7; #define ll long Long#define CL (b) memset (A,b,sizeof (a)) #define Lson (i<<1) #define Rson ((i<<1) | |) #define N 50010in T gcd (int a,int b) {return B?GCD (b,a%b): A;} int main () {int n,m,a,b,k; Double x = (1 + sqrt (5.0))/2.0; while (scanf ("%d%d", &a,&b), (a+b)) {if (a>b) swap (A, b); K = b-a; if (a== (int) (K*X)) cout<<0<<endl; else {cout<<1<<endl; for (int i=1; i<=a; i++) {n = a-i; m = b-i; K = M-n; if (n== (int) (k*x)) cout<<n<< "" <<m<<endl; } for (int i=b-1; i>=0; i--) {n = A; m = i; if (n>m) Swap (n, m); K = M-n; if (n== (int) (k*x)) cout<<n<< "" <<m<<endl; }}} return 0;}
hdu2177 (2 stacks) Stone game (Witzov game)