题目链接:HDU 2999【Stone Game, Why are you always there?】
思路
由于只能取连续的一段石子,当取出的石子是这段石子的中间一部分时就相当于将一段石子分成两段石子,简单异或一下求SG值就行了
代码
int sg[N], vis[N], a[N];
int n, m, k;
void getsg() {
memset(sg, 0, sizeof sg);
memset(vis, 0, sizeof vis);
for (int i = 1; i <= 1000; i++) {
for (int j = 1; a[j] <= i && j <= n; j++) {
for (int k = 0; k <= i - a[j]; k++)
//枚举从这一段的哪一个石子开始取连续的a[j]个棋子
vis[sg[k] ^ sg[i - a[j] - k]] = i;
}
while (vis[sg[i]] == i) {
sg[i]++;
}
}
}
int main() {
while (~scanf("%d", &n)) {
for (int i = 1; i <= n; i++) {
a[i] = read();
}
sort(a + 1, a + 1 + n);
getsg();
m = read();
while (m--) {
k = read();
if (sg[k])
puts("1");
else
puts("2");
}
}
return 0;
}
标签:2999,HDU,there,int,always,石子,vis,sg
From: https://www.cnblogs.com/againss/p/18362460