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. java===java习题---Josephu问题

    package testbotoo; /** * * @author */ public class Demo4 { public static void main(String[] args) { ...

  2. java===java基础学习(10)---对象构造

    重载 如果多个方法有相同的名字,不同的参数,便产生了重载.编译器必须挑选出具体执行哪个方法,他通过用各个方法给出的参数类I型那个与特定方法调用所使用的值类型进行匹配来挑选出相应的方法.如果编译器找不到 ...

  3. 【COGS2622】后缀平衡树

    这是个后缀平衡树的裸题.... 然后傻逼的我调了一下午. #include<bits/stdc++.h> typedef long long ll; using namespace std ...

  4. 神奇JavaScript框架---Top5

    前言 个人观点,供您参考 观点源自作者的使用经验和日常研究 排名基于框架的受欢迎度, 语法结构, 易用性等特性 希望大家能够基于此视频找到最适合自己的框架 下面介绍的都是严格的前端框架和库 前言 To ...

  5. java 查看运行时某个类文件所在jar的位置

    在一些大型项目中,项目所依赖的库可能比较到,有时候也会出现库冲突的情况,曾经遇到过一种情况:一个第三方云存储提供了一个sdk,这个sdk本身依赖httpclient相关的包,然而对方却把httpcli ...

  6. 使用JMX工具远程监控tomcat配置

    使用JMX工具远程监控tomcat,在tomcat启动时添加配置参数: -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.po ...

  7. MySQL:按后缀缀批量删除表格

    Select CONCAT( 'drop table ', table_name, ';' ) FROM information_schema.tables Where table_schema='s ...

  8. python插入oracle数据

    # coding=utf- ''''' Created on -- @author: ''' import json; import urllib2 import sys import cx_Orac ...

  9. java中this的用法如:this.name=name

    package com.chensi; /** * 这个是为了搞懂那个 this.name = name的. * @author ZHL * */ public class ThisTestZhl { ...

  10. C10问题

    C10K问题是指服务器同时支持成千上万个客户端的问题,也就是concurrent 10 000 connection(这也是C0K这个名字的由来).由于硬件成本幅度降低和硬件版本的提高,如果服务器能够 ...