HDU 1848 Fibonacci again and again
2011-08-19 00:30
591 查看
取石子游戏,决策是从某一堆取Fibonacci数的石子,计算SG函数即可。延续一贯的怪异风格,GCC编译。
1 //+option:-ansi -Wall -Wextra
2 //+task:hdu 1848
3 //press <F7> to update the source to mark file.
4 //press <S-F7> to open the page
8 #include"cstdio"
11 using namespace std;
34 #define _concat(a, b) a##b
35 #define concat(a, b) _concat(a,b)
36 #define Static\
37 __attribute__((constructor))void concat(prework__,__LINE__)()
38 /* Good Day*/
39 int F[21];
40 int SG[100010];
41 int a[1010];
42 int bitscan[1025];
43
44 Static{
45 F[0] =1;
46 F[1] =1;
47 for (int i=1, j=0;
j<=10; i*=2, j++) bitscan[i] = j;
48 for (int i=2; i<20;
i++) F[i] = F[i-1] + F[i-2];
49 SG[0]=0;
50 for (int i=1; i<=1000;
i++)
51 {
52 int mysg =0;
53 for (int j=1; j<20;
j++)
54 if (i >= F[j])
55 mysg |= (1<<(SG[i-F[j]]));
56 #define lowbit(a) ((a)&(-(a)))
57 SG[i] = bitscan[lowbit(~mysg)];
58 }
59 }
60 /* Good Day*/
61
62 int main()
63 {
64 int N, M, P;
65 while (scanf("%d%d%d",
&N, &M, &P)!=EOF && N||M||P)
66 {
67 if ( (SG
^SG[M]^SG[P]) ==0)
68 printf("Nacci\n");
69 else
70 printf("Fibo\n");
71 }
72 }
73
74
1 //+option:-ansi -Wall -Wextra
2 //+task:hdu 1848
3 //press <F7> to update the source to mark file.
4 //press <S-F7> to open the page
8 #include"cstdio"
11 using namespace std;
34 #define _concat(a, b) a##b
35 #define concat(a, b) _concat(a,b)
36 #define Static\
37 __attribute__((constructor))void concat(prework__,__LINE__)()
38 /* Good Day*/
39 int F[21];
40 int SG[100010];
41 int a[1010];
42 int bitscan[1025];
43
44 Static{
45 F[0] =1;
46 F[1] =1;
47 for (int i=1, j=0;
j<=10; i*=2, j++) bitscan[i] = j;
48 for (int i=2; i<20;
i++) F[i] = F[i-1] + F[i-2];
49 SG[0]=0;
50 for (int i=1; i<=1000;
i++)
51 {
52 int mysg =0;
53 for (int j=1; j<20;
j++)
54 if (i >= F[j])
55 mysg |= (1<<(SG[i-F[j]]));
56 #define lowbit(a) ((a)&(-(a)))
57 SG[i] = bitscan[lowbit(~mysg)];
58 }
59 }
60 /* Good Day*/
61
62 int main()
63 {
64 int N, M, P;
65 while (scanf("%d%d%d",
&N, &M, &P)!=EOF && N||M||P)
66 {
67 if ( (SG
^SG[M]^SG[P]) ==0)
68 printf("Nacci\n");
69 else
70 printf("Fibo\n");
71 }
72 }
73
74
相关文章推荐
- HDU 1848 Fibonacci again and again(SG函数)
- HDU 1848 Fibonacci again and again(博弈论:sg函数)
- hdu1848 Fibonacci again and again(博弈)
- HDU1848-Fibonacci again and again
- hdu 1848 Fibonacci again and again
- hdu 1848 Fibonacci again and again 博弈论,求出SG函数,,什么问题都没有了
- HDU 1848 Fibonacci again and again
- 【HDU 1848 Fibonacci again and again】 + sg函数
- HDU 1848 Fibonacci again and again
- HDU 1848 Fibonacci again and again (斐波那契博弈SG函数)
- HDU 1848 Fibonacci again and again
- [HDU 1848]Fibonacci again and again(博弈论)
- hdu 1848 Fibonacci again and again
- HDU - 1848 Fibonacci again and again(sg函数)
- HDU 1848 -Fibonacci again and again 博弈论
- hdu 1848 Fibonacci again and again sg定理
- HDU1848_Fibonacci again and again_经典的求sg
- hdu1848 Fibonacci again and again (博弈论sg函数模板)
- HDU 1848 Fibonacci again and again
- hdu 1848 Fibonacci again and again (sg函数)