HDU 2177 (2 heap) Stone game wythoff Game + output Solution

Source: Internet
Author: User

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 ;}

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.