HDU4664 Triangulation sg函数

来源:互联网 发布:如何提高免疫力 知乎 编辑:程序博客网 时间:2024/04/29 03:16

题目链接:HDU4664

Triangulation

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


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
21222 2
 

Sample Output
CarolDave
 

题意:一堆平面,每个平面一堆点,2人轮流在平面上连线,要求只能在同一平面上连,并且不可以相交或构成三角形,问谁会赢。

按照要求构建sg函数即可,每次连线都不可以相交,所以每连一条线就相当于把平面一分为二为2个字问题,打表求sg函数即可。由于数据量比较大,所以找规律,发现后面是有循环节的,求循环节即可。

////  main.cpp//  HDU4664////  Created by teddywang on 2016/9/6.//  Copyright © 2016年 teddywang. All rights reserved.//#include <iostream>#include<cstdio>#include<algorithm>#include<cstring>using namespace std;int T,n;int sg[250];int mex(int x){    if(sg[x]>=0) return sg[x];    int vis[40];    memset(vis,0,sizeof(vis));    for(int i=0;i<x-1;i++)    {        sg[i]=mex(i);        sg[x-i-2]=mex(x-i-2);        vis[sg[i]^sg[x-i-2]]=1;    }    for(int i=0;;i++)    {        if(!vis[i])            return i;    }}void getsg(){    memset(sg, -1, sizeof(sg));    sg[0]=0;    sg[1]=0;    sg[2]=1;    sg[3]=1;    for(int i=0;i<230;i++)    {        sg[i+4]=mex(i+4);    }}int SG(int x){    if(x<200) return sg[x];    else{        x%=34;        return sg[x+4*34];    }}int main(){    getsg();    //for(int i=0;i<200;i++)      //  cout<<sg[i]<<endl;    cin>>T;    while(T--)    {        scanf("%d",&n);        int ans=0;        for(int i=0;i<n;i++)        {            int num;            scanf("%d",&num);            ans^=SG(num);        }        if(ans==0) printf("Dave\n");        else printf("Carol\n");    }}


0 0
原创粉丝点击