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; }
相关文章推荐
- 地理位置查询附近商家
- adb常用命令
- ecshop中smarty最常用的6大基本语法
- 深入浅出 React Native:使用 JavaScript 构建原生应用
- 操作系统与网络实现 之七
- c++虚函数
- 指针、数组
- Course Schedule
- hdu 4662 MU Puzzle(水)
- Android如何获取asset目录下所有文件的路径
- 汇编语言 用户名密码登录验证程序 (dos调用)
- 愤怒的小鸟-物理世界Box2d(1)-静态刚体的创建
- 百度地图的底层地图数据从哪儿来?
- Android笔记(五十二) 侧滑菜单SlidingMenu
- just do it
- 在qt中安装使用mysql
- 创建的Android avd只有屏幕,没有返回等操作键
- hdu 4661 Message Passing(树形dp)
- qq侧滑菜单的简单实现
- shell脚本操作mysql数据库