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)