zoukankan      html  css  js  c++  java
  • HDU 4664 Triangulation(2013多校6 1010题,博弈)

    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.
     
     
    然后胡搞下就过了
     
     
     1 /*
     2  * Author:  kuangbin
     3  * Created Time:  2013/8/8 11:54:23
     4  * File Name: 1010.cpp
     5  */
     6 #include <iostream>
     7 #include <cstdio>
     8 #include <cstdlib>
     9 #include <cstring>
    10 #include <cmath>
    11 #include <algorithm>
    12 #include <string>
    13 #include <vector>
    14 #include <stack>
    15 #include <queue>
    16 #include <set>
    17 #include <time.h>
    18 using namespace std;
    19 const int MAXN = 100010;
    20 int sg[MAXN];
    21 bool vis[MAXN];
    22 int mex(int x)
    23 {
    24 
    25     if(sg[x]!=-1)return sg[x];
    26     if(x == 0)return sg[x] = 0;
    27     if(x == 1)return sg[x] = 0;
    28     if(x == 2)return sg[x] = 1;
    29     if(x == 3)return sg[x] = 1;
    30     memset(vis,false,sizeof(vis));
    31     for(int i = 0;i < x-1;i++)
    32         vis[mex(i)^mex(x-i-2)] = true;
    33     for(int i = 0;;i++)
    34         if(!vis[i])
    35             return sg[x] = i;
    36 }
    37 
    38 int SG(int x)
    39 {
    40     if(x <= 200)return sg[x];
    41     else
    42     {
    43         x %= 34;
    44         x += 4*34;
    45         return sg[x];
    46     }
    47 }
    48 
    49 int main()
    50 {
    51     //freopen("in.txt","r",stdin);
    52     //freopen("out.txt","w",stdout);
    53     memset(sg,-1,sizeof(sg));
    54     for(int i = 0;i <= 1000;i++)
    55     {
    56         sg[i] = mex(i);
    57     }
    58     int T;
    59     int n;
    60     int a;
    61     scanf("%d",&T);
    62     while(T--)
    63     {
    64         scanf("%d",&n);
    65         int sum = 0;
    66         for(int i = 0;i < n;i++)
    67         {
    68             scanf("%d",&a);
    69             sum ^= SG(a);
    70         }
    71         if(sum)printf("Carol
    ");
    72         else printf("Dave
    ");
    73     }
    74     return 0;
    75 }
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
  • 相关阅读:
    一个十年java程序员的心得
    程序员每天应该思考的5个问题,你有思考过吗?
    Java---Java的面试题(二)
    Java---Java的面试题(一)
    java中的几种取整函数
    mysql ,为什么一张表的varchar关联另一张表varchar执行失败的一个原因
    可注册两位字母+两位数字com域名大全(到2016-5-12:12时候)
    更改(修改)mysql自动增序列改变从1000开始
    HTTP状态码(HTTP Status Code)
    struts2、jsp的简单路径的简单拦截
  • 原文地址:https://www.cnblogs.com/kuangbin/p/3246475.html
Copyright © 2011-2022 走看看