[博弈论]Triangulation

Triangulation

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

 

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

2013 Multi-University Training Contest 6
 

#include <cstdlib>
#include <cmath>
#include <cstdio>

using namespace std;

const int sg[] = {0, 0, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 0, 5, 2, 2, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 2, 7, 4, 0, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 2, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4};
const int cir[] = {4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4};

int compute(int count) {
    if (count < 69) {
        return sg[count];
    }

    count %= 34;
    return cir[count];
}

int main()
{
    int i, num;
    int j, group;
    int value;

    int sum = 0;
    
    scanf("%d", &num);

    for (i = 0; i < num; ++i) {
        scanf("%d", &group);
        sum = 0;
        for (j = 0; j < group; ++j) {
            scanf("%d", &value);
            sum = sum ^ compute(value);
        }

        if (sum > 0) {
            printf("Carol\n");
        } else {
            printf("Dave\n");
        }
    }

    return 0;
}

猜你喜欢

转载自blog.csdn.net/micklongen/article/details/90049793