Hdu 2516 Take the stone game Fibonacci The game entry question

Source: Internet
Author: User

Take a stone gameTime limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 3069 Accepted Submission (s): 1784


Problem Description1 Heap of stones There are N, two people take turns. The 1th time the first person can take any number, but not all of them. The number of stones to be taken at a later time cannot exceed twice times the number of previous fetching. The winner wins. The first to take the negative output "Second win". The first winner wins the output.

Input inputs have multiple groups. The 1th row of each group is 2<=n<2^31. N=0 exit.

Output "Second win". The first winner wins the output.
See sample Output.

Sample Input
213100000

Sample Output
Second Winsecond Winfirst win

Sourceecjtu Autumn Contest Some topics and models of game theory, see this blog about some game model summary, Bashbor + Witzov game + Nimbo Games + Fair combination game. Some of the information on the Internet summed up a little bit, the direct code:
#include <stdio.h> #include <limits.h> #define LEN 50long long a[len]; int Cnt;bool search (long long x) {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{return true;}} return false;} int main () {long long n; a[1] = 1, a[2] = 2; for (int i = 3; i < LEN; ++i) {if (a[i-1]+a[i-2] > Int_max) {cnt = i-1; br Eak;} A[i] = a[i-1]+a[i-2];} while (~SCANF ("%i64d", &n) && n) {int flag = search (n); if (flag) {puts ("Second win");} Else{puts ("first win");}} return 0;}

with June

Hdu 2516 Take the stone game Fibonacci The game entry question

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.