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. sk_buff结构

    sk_buff结构用来描述已接收或者待发送的数据报文信息:skb在不同网络协议层之间传递,可被用于不同网络协议,如二层的mac或其他链路层协议,三层的ip,四层的tcp或者udp协议,其中某些成员变量 ...

  2. centos_7.1.1503_src_7

    http://vault.centos.org/7.1.1503/os/Source/SPackages/ tex-fonts-hebrew-0.1-21.el7.src.rpm 05-Jul-201 ...

  3. 2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6154 CaoHaha's staff 思维

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6154 题意:在笛卡尔坐标系下,画一个面积至少为  n 的简单多边形,每次只能画一条边或者一个格子的对角 ...

  4. 阿里云ECS的使用

    一.阿里云ECS的使用 1.Linux CentOS Ubuntu Readhat 2.远程登录 xshell 远程登录 winScp 远程文件操作 3.Linux命令 cd 目录名 ls . ls ...

  5. python_day2学习笔记

    基本数据类型 1.数字 int(整型) 在32位机器上,整数的位数为32位,取值范围为-2**31-2**31-1,即-2147483648-2147483647 在64位系统上,整数的位数为64位, ...

  6. nginx中使用perl模块

    转载自:http://www.netingcn.com/nginx-perl.html 如果对于一个绝大部分内容是静态的网站,只有极少数的地方需要动态显示,碰巧你又了解一点perl知识,那么nginx ...

  7. 将对象转换为JSON字符串

    将对象转换为JSON串: 方案一: 可以通过json-lib工具jar包进行转化:在www.json.org官网下载jar包. 方案二: 通过ObjectMapper对象进行转换 需要引入相应的jar ...

  8. 图片乱码问题 解决方法 php

    两个开发者都是下载同一个项目的git代码,但到本地环境,一个可以正常显示图片验证码,一个不行,找个半天开始以为环境问题 找了半天 不是 很多没说到重点 其实不只是当前文件格式问题 也要考虑其他调用文件 ...

  9. React Native 0.56.1初始化项目运行出现错误(Module `AccessibilityInfo` does not exist in the Haste module map)

    当使用react-native init myApp初始化项目时,出现以下错误 出现以上错误的原因是因为0.56.1版本初始化项目就有问题,请见 https://github.com/facebook ...

  10. 160. Intersection of Two Linked Lists【Easy】【求两个单链表的第一个交点】

    Write a program to find the node at which the intersection of two singly linked lists begins. For ex ...