nyoj 358 Take stones (5) (Fibonacci game)

Take stones (5)

Time Limit: 1000  ms | Memory Limit: 65535  KB
Difficulty: 4
describe
himdd wanted to play a game recently, so he found acmj to play with him, the game is like this: there is a pile of stones, two people take turns to take a certain amount of stones from it, and the person who takes all the stones at the end is the winner, but the following rules must be followed :
1. The first time you can't take it all, take at least 1 piece.

2. From the second time onwards, the number of stones each player takes is at least 1, and at most twice the number of stones the opponent just took.

himdd wants to know in advance if he will win, can you help him? (every time himdd goes first)

enter
There are multiple sets of test data, each set has an integer n (2<=n<2^64);
output
himdd will win and output Yes, otherwise, output No;
sample input
2
5
6
Sample output
No
No
Yes

Conclusion: As long as n appears in the Fibonacci sequence (1, 2, 3, 5, 8, 13...), the first mover will lose.

#include<stdio.h>
#include<algorithm>
using namespace std;
const int maxn=105;
long long a[maxn];
intmain()
{
	a[0]=0;a[1]=1;
	for(int i=2;i<maxn;i++)
		a[i]=a[i-1]+a[i-2];
	long long n;
	while(~scanf("%lld",&n))
	{
		if(*lower_bound(a,a+maxn,n)==n)
		{//Binary search
			printf("No\n");
		}
		else printf("Yes\n");
	}
	
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325939522&siteId=291194637