您的位置:首页 > 大数据 > 人工智能

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: