Reprinted please indicate the source, thank youHttp://blog.csdn.net/ACM_cxlove? Viewmode = Contents
By --- cxlove
HDU 2177 (2 heap) Stone game wythoff Game + output Solution
Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 2177
The output scheme is complicated. The data is not very big. First, we need to list all the strange situations in whthoff.
Then, you can determine whether it is a winning situation. ,
If it wins, first determine whether it can be directly reduced at the same time. The traversal or binary search is not required here. Because the two subtract a number at the same time, their difference remains unchanged, and aK = K * (SQRT (5) + 1), BK = ak + K;
The difference between the two can be directly located and then determined.
In another case, if one of the two numbers is subtracted and a singular situation is obtained, the Case-Based Binary Search is performed.
Pay attention to some details
# Include <iostream> # include <cstdio> # include <cstring> # include <algorithm> # include <cmath> # include <vector> # include <string> # include <map> # define ll long # define n 1000000 # define INF 1 <20 using namespace STD; int A [500000], B [500000], CNT; void search1 (INT N, int m) {int low = 0, high = CNT, mid; while (low <= high) {mid = (high + low)> 1; if (n = A [Mid]) {If (M> B [Mid]) printf ("% d \ n", a [Mid], B [Mid]); return;} if (a [Mid] <n) Low = mi D + 1; elsehigh = mid-1 ;}} void search2 (int n, int m) {int low = 0, high = CNT, mid; while (low <= high) {mid = (high + low)> 1; if (n = B [Mid]) {If (M> A [Mid]) printf ("% d \ n", a [Mid], B [Mid]); return;} If (B [Mid] <n) Low = Mid + 1; elsehigh = mid-1 ;}} int main () {for (INT I = 0; I <500000; I ++) {A [I] = (INT) (I * (SQRT (5.0) + 1)/2); B [I] = A [I] + I; If (B [I]> = 1000000) {CNT = I; break;} int n, m; while (scanf ("% d", & N, & M )! = EOF & N + M) {If (n> m) Swap (n, m); If (n = (INT) (SQRT (5.0) + 1) * (m-N)/2) printf ("0 \ n"); else {printf ("1 \ n "); if (m-n <CNT & N-A [M-N] = m-B [M-N]) printf ("% d \ n ", A [M-N], B [M-N]); search1 (n, m); If (n! = M) search1 (m, n); search2 (n, m); If (n! = M) search2 (m, n) ;}return 0 ;}