Fibonacci again and againTime limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 5596 Accepted Submission (s): 2354
Problem description Any college student should not be unfamiliar with the Fibonacci (Fibonacci numbers), which is defined as:
F (1) = 1;
F (2) = 2;
F (n) =f (n-1) +f (n-2) (n>=3);
So, 1,2,3,5,8,13 ... is the Fibonacci series.
There are a lot of related topics in hdoj, such as 1005 Fibonacci again is once the Zhejiang province game problem.
Today, another topic about Fibonacci appears, it is a small game, defined as follows:
1, this is a two-person game;
2, a total of 3 piles of stones, the number is M, N, p;
3, two people take turns;
4, each step can choose any heap of stones, and then take away F;
5, F can only be the element in the Fibonacci sequence (that is, each time only take 1,2,3,5,8 ... Quantity);
6, the first to take the light of all the stones of the person who wins;
Assuming both sides use the optimal strategy, judge whether the person who wins the game will win or the person who will win.
Input data contains multiple test cases, one row for each test case, and 3 integer m,n,p (1<=m,n,p<=1000).
M=n=p=0 indicates the end of the input.
Output if the initiator can win, please export "Fibo", otherwise output "Nacci", the output of each instance occupies one row.
Sample Input
1 1 11 4 10 0 0
Sample Output
FiboNacci
Do not know why,, at first, always wrong, and do not know what to change, on a. Anyway, I feel this problem is very water, and still engaged in such a long time.
Code:
#include <stdio.h> #include <string.h> #define MAX 1010int fib[30], sg[max];void GETSG () {bool Visited[max]; for (int i = 1; i < MAX; ++i) {memset (visited,false,sizeof (visited)), for (int j = 1; I-fib[j] >= 0; ++j) {VISITED[SG [I-fib[j]] = true;} for (int j = 0; J < MAX, ++j) {if (!visited[j]) {sg[i] = J; break;}}} int main () {fib[1] = 1, fib[2] = 2, for (int i = 3; i <; ++i) {fib[i] = fib[i-1]+fib[i-2]; if (fib[i]>1000) {break; }}int m, n, p; GETSG (); while (~SCANF ("%d%d%d", &m,&n,&p) && (m| | n| | p) {int ans = sg[m]^sg[n]^sg[p], if (ans) {puts ("Fibo");} Else{puts ("Nacci");}} return 0;}
with June
HDU 1848 Fibonacci again and again game theory, to find out the SG function, no problem.