1873. The finale or the match?
Constraints
Time Limit: 1 secs, Memory Limit: 32 MB
Description
Alice:Bob, the finale of the teleplay “Catch the uncatchable” is going to be on tonight.
Bob:Alice, there is going to be a football match too, China VS Japan. It must be very drastic and stirring. Why not watch it instead?
Alice:But the comedy is so attractive and humorous that I’ve been anxious for it all day long. Contrarily, the football match is too boring. Just a crowd of men chase and kick the ball……
How could Alice catch the feeling of Bob’s, a super football fans. His enthuse over the match is like that of Alice’s over the teleplay. He wouldn’t concede and, at the same time, wouldn’t make Alice unhappy either.
Bob:Alice, let’s play the finger-guessing game. The one who wins makes the decision.
Alice:No, it depends on luck. Emm, see that pile of stones?
Finally they come to a compromise:Take the stone game.
There are N stones. Alice and Bob take turns to remove any number of stones from that pile. The first player takes away a certain number of stones (but no more than N). The second player does the same things likewise, and then comes the first player’s turn. Each time the player could take away at least one stone and no more than twice as many as the ones the last player removes. He who removes the last stone wins the game. Suppose that both Alice and Bob are very smart. Neither of them will make any mistake during the game. Of course, who wants to loose the chance to watch his favorite program? Bob, a gentleman, would let Alice take first.
Please give your hand to Alice to decide whether she has a winning strategy.
Input
The first line in the input is an integer T, indicating that there are T test cases. The next T lines consist of T positive integers, each one per line. All of the integers are more than 1 and less than 2^31.
Output
For each test case, output NO in one line if Alice will surely win or YES otherwise.
Sample Input
2 3 4
Sample Output
YESNO
// Problem#: 1873 // Submission#: 3344924 // The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License // URI: http://creativecommons.org/licenses/by-nc-sa/3.0/ // All Copyright reserved by Informatic Lab of Sun Yat-sen University #include <algorithm> #include <iostream> #include <string> #include <stdio.h> #include <queue> #include <string.h> #include <vector> #include <iomanip> #include <map> #include <stack> #include <functional> #include <list> #include <cmath> using namespace std; int main() { std::ios::sync_with_stdio(false); int caseNum; cin >> caseNum; while (caseNum--) { int temp; cin >> temp; long long fi2 = 2; long long fi1 = 3; long long f = fi1 + fi2; bool lose = false; if (temp == fi2 || temp == fi1 || temp == 1) lose = true; while (temp >= f) { if (temp == f) { lose = true; break; } fi2 = fi1; fi1 = f; f = fi1 + fi2; } cout << (lose ? "YES" : "NO") << endl; } //getchar(); //getchar(); return 0; }