Hdu 2177 Take (2 heap) game theory of stone games, Witzov, improve the problem, but the test data is extremely water

Source: Internet
Author: User

Take (2 piles) Stone gameTime limit:3000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 1291 Accepted Submission (s): 764

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 Input
1 2 5 84 72 20 0

Sample Output
014 73 5010) 01 2

Reprint please declare blog original address: http://blog.csdn.net/lionel_d
The test data of this problem is extremely water, and the online part of the human code is fundamentally wrong. I refer to the code written by http://www.cnblogs.com/kuangbin/archive/2011/08/28/2156426.html himself:
#include <stdio.h> #include <math.h> #define MAX 500010int A[max],b[max], cnt = 0;bool find1 (int x, int y) {int s = 1, E = Cnt;while (s<=e) {int mid = (s+e) >>1, if (X>a[mid]) {s = mid + 1;} else if (X<a[mid]) {e = mid-1;} Else{if (Y>b[mid]) {printf ("%d%d\n", A[mid],b[mid]);} else{printf ("%d%d\n", x*y-x,y-2*x+x*y);//Refer to the online formula}return True;}} return false;} BOOL Find2 (int x, int y) {int s = 1, E = Cnt;while (s<=e) {int mid = (s+e) >>1, if (X>b[mid]) {s = mid + 1;} else if (X<b[mid]) {e = mid-1;} else{printf ("%d%d\n", A[mid],b[mid]); return true;}} return false;} int main () {int n, m;double p = (sqrt (5.0) +1)/2, for (int i = 0; i < MAX; ++i) {a[i] = (int) (i*p); B[i] = a[i] + i; if ( B[i]>2*max) {cnt = i; break;}} while (~SCANF ("%d%d", &m,&n) && (m| | N)) {if (m>n) {int temp = m; m = n; n = temp;} if (m = = (int) ((n-m) *p)) {puts ("0"); continue;} Puts ("1"), if (n-m = = B[n-m]-a[n-m] && a[n-m]<m) {printf ("%d%d\n", a[n-m],b[n-m]);} if (!find1(M,n)) {Find2 (m,n);}} return 0;}

with June

Hdu 2177 Take (2 heap) game theory of stone games, Witzov, improve the problem, but the test data is extremely water

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.