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