题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1083
题意差不多是这样,给你n条线的长度,让你染色,每次只能染2个长度单位,让你先染,问是否能赢的胜利
其实这题和取石子的那题(ECNU 1328 Stripes )差不多,都要考虑子情况,一条线染色后变成两段,要分别考虑
上个代码:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44 |
#include <stdlib.h>#include <stdio.h>#include <string.h>int f[100],sg[100],hash[100];void
GetSG(){ int
i,j; memset(sg,0,sizeof(sg)); for(i=2;i<=51;i++) { memset(hash,0,sizeof(hash)); for(j=0;j<=i-2;j++) { hash[sg[j]^sg[i-j-2]]=1; } for(j=0;j<=51;j++) { if(hash[j]==0) { sg[i]=j; break; } } }}int
main(){ int
i,j,n,m; GetSG(); while(scanf("%d",&n)!=EOF) { int
flag=0; for(i=0;i<n;i++) { scanf("%d",&m); flag^=sg[m]; } if(flag==0) printf("No\n"); else
printf("Yes\n"); } return
0;} |
zoj 2083 Win the Game(博弈SG函数),布布扣,bubuko.com
原文:http://www.cnblogs.com/ccccnzb/p/3734611.html