Triangulation

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 96    Accepted Submission(s): 29

Problem Description
There are n points in a plane, and they form a convex set.

No, you are wrong. This is not a computational geometry problem.

Carol
and Dave are playing a game with this points. (Why not Alice and Bob?
Well, perhaps they are bored. ) Starting from no edges, the two players
play in turn by drawing one edge in each move. Carol plays first. An
edge means a line segment connecting two different points. The edges
they draw cannot have common points.

To make this problem a bit
easier for some of you, they are simutaneously playing on N planes. In
each turn, the player select a plane and makes move in it. If a player
cannot move in any of the planes, s/he loses.

Given N and all n's, determine which player will win.

 
Input
First line, number of test cases, T.
Following are 2*T lines. For every two lines, the first line is N; the second line contains N numbers, n1, ..., nN.

Sum of all N <= 106.
1<=ni<=109.

 
Output
T lines. If Carol wins the corresponding game, print 'Carol' (without quotes;) otherwise, print 'Dave' (without quotes.)
 
Sample Input
2
1
2
2
2 2
 
Sample Output
Carol
Dave
 
Source
 
Recommend
zhuyuanchen520
 
 
 
 
这题一开始看错题目意思了。
 
导致连SG函数转移都写不出来。
 
其实这题看懂了就很好搞了。
 
每次加边,不能形成三角形,所以肯定不加共点的边,否则就是自杀。
 
x个点,转移后相当于 i    ,    x-i-2 .加的那两个点去掉了。
 
 
SG函数打表以后,很明显是要找规律。
发现周期是34.
而且周期要到后面才有周期。
 
所以前面打表,后面利用周期。
 
可以参考下oeis,发现这个是经典的问题。Sprague-Grundy values for Dawson's Chess
 
Has period 34 with the only exceptions at n=0, 14, 16, 17, 31, 34 and 51.
 
 
然后胡搞下就过了
 
 
 /*
* Author: kuangbin
* Created Time: 2013/8/8 11:54:23
* File Name: 1010.cpp
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <time.h>
using namespace std;
const int MAXN = ;
int sg[MAXN];
bool vis[MAXN];
int mex(int x)
{ if(sg[x]!=-)return sg[x];
if(x == )return sg[x] = ;
if(x == )return sg[x] = ;
if(x == )return sg[x] = ;
if(x == )return sg[x] = ;
memset(vis,false,sizeof(vis));
for(int i = ;i < x-;i++)
vis[mex(i)^mex(x-i-)] = true;
for(int i = ;;i++)
if(!vis[i])
return sg[x] = i;
} int SG(int x)
{
if(x <= )return sg[x];
else
{
x %= ;
x += *;
return sg[x];
}
} int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
memset(sg,-,sizeof(sg));
for(int i = ;i <= ;i++)
{
sg[i] = mex(i);
}
int T;
int n;
int a;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
int sum = ;
for(int i = ;i < n;i++)
{
scanf("%d",&a);
sum ^= SG(a);
}
if(sum)printf("Carol\n");
else printf("Dave\n");
}
return ;
}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

HDU 4664 Triangulation(2013多校6 1010题,博弈)的更多相关文章

  1. HDU 4705 Y (2013多校10,1010题,简单树形DP)

    Y Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submiss ...

  2. HDU 4685 Prince and Princess (2013多校8 1010题 二分匹配+强连通)

    Prince and Princess Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Othe ...

  3. HDU 4675 GCD of Sequence (2013多校7 1010题 数学题)

    GCD of Sequence Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)T ...

  4. HDU 4678 Mine (2013多校8 1003题 博弈)

    Mine Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submis ...

  5. HDU 4630 No Pain No Game(2013多校3 1010题 离线处理+树状数组求最值)

    No Pain No Game Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  6. HDU 4768 Flyer (2013长春网络赛1010题,二分)

    Flyer Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  7. HDU 4747 Mex (2013杭州网络赛1010题,线段树)

    Mex Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submis ...

  8. HDU 4704 Sum (2013多校10,1009题)

    Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submi ...

  9. HDU 4699 Editor (2013多校10,1004题)

    Editor Time Limit: 3000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Su ...

随机推荐

  1. 安全测试===burpsuit指南

    网址: https://www.gitbook.com/book/t0data/burpsuite/details 引子 刚接触web安全的时候,非常想找到一款集成型的渗透测试工具,找来找去,最终选择 ...

  2. eComStation 1.2

    https://thomas0008.ctfile.com/u/75519/87485 https://thomas0008.ctfile.com/downhtml/75519/428846/1508 ...

  3. WoW[www]

    WoWBeez https://github.com/StealtheeEU/WoWBeez https://github.com/mtucker6784/Elysium https://github ...

  4. 在Github里集成Readthedocs服务

    Readthedocs支持Markdown格式和sphinx格式的文档排版,是部署项目文档的绝佳平台.利用Github的托管服务,我们可以方便地将文档托管于Github,并利用Readthedocs查 ...

  5. 2015多校第6场 HDU 5361 并查集,最短路

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5361 题意:有n个点1-n, 每个点到相邻点的距离是1,然后每个点可以通过花费c[i]的钱从i点走到距 ...

  6. sql server 学习笔记

    1. 修改student表中sdept字段改为varchar类型,长度为30,并且不为空 ) not null 2. 删除student表中的address列 alter table student ...

  7. linux 设置开机启动项两种方式

    原文链接:http://blog.csdn.net/karchar/article/details/52489572 有时候我们需要Linux系统在开机的时候自动加载某些脚本或系统服务. 在解问题之前 ...

  8. leetcode 之Copy List with Random Pointer(23)

    深拷贝一个链表,不同的是这个链表有个额外的随机指针.参考:http://blog.csdn.net/ljiabin/article/details/39054999 做法非常的巧妙,分成三步,一是新建 ...

  9. POJ 1456 Supermarket(贪心+并查集)

    题目链接:http://poj.org/problem?id=1456 题目大意:有n件商品,每件商品都有它的价值和截止售卖日期(超过这个日期就不能再卖了).卖一件商品消耗一个单位时间,售卖顺序是可以 ...

  10. ZOJ-3319

    Islands Time Limit: 1 Second      Memory Limit: 32768 KB There are N islands and some directed paths ...