您的位置:首页 > 其它

hdu 4664 Triangulation(博弈)

2015-11-06 21:37 309 查看
题目链接:hdu 4664 Triangulation

解题思路

根据SG定理打个表,SG值最多为9,前几项在SG值不全的时候没有规律,但是当SG值为9的出现后,以34为一循环。

代码

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int sg[] = {0, 0, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 0, 5, 2, 2, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 2, 7, 4, 0, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 2, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4};
const int cir[] = {4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4};

int SG (int x) {
if (x < 69) return sg[x];
x %= 34;
return cir[x];
}

int main() {
int cas;
scanf("%d", &cas);
while (cas--) {
int n, x, s = 0;
scanf("%d", &n);
while (n--) {
scanf("%d", &x);
s ^= SG(x);
}
printf("%s\n", s ? "Carol" : "Dave");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: