HDU 2516 (game)

Source: Internet
Author: User

Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=2516

Take a stone game

Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others) total submission (s): 2994 Accepted Submission (s): 1748

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 Input213100000 Sample Outputsecond Winsecond Winfirst win analysis: Simulation of some data can find the law, through the simulation can know that the second person wins is a Fibonacci sequence.
1#include <cstdio>2#include <cstring>3#include <cmath>4#include <iostream>5#include <algorithm>6 using namespacestd;7 8 intf[ -];9 Ten intMain () One { A     intN; -     intI,j,ok; -      while(SCANF ("%d", &n) = =1&&N) the     { -f[1] =2; -f[2] =3; -          for(i=3; i< $; i++) +F[i] = f[i-1] + f[i-2]; -OK =0; +          for(j=1; j< $; J + +) A         { at             if(n = =F[j]) -             { -OK =1; -                  Break; -             } -         } in         if(OK) -printf ("Second win\n"); to         Else +printf ("First win\n"); -     } the     return 0; *}
View Code

HDU 2516 (game)

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.