题意:
N个平面,每个平面有ni个点,组成凸多边形,两个人玩游戏,划线,他们可以划任意一个平面的两个点,有以下要求:两个人划得线不能交叉,不要划已经划过的线,如果一个平面被划了一个空心的三角形,那么这个平面就不能继续划线了。Carol先来,两个人轮着画,谁没线划了就输了,问你最后谁赢。
思路:
sg函数暴力求法:
一个平面上连接点时,不能连接已经有边的顶点,因为对方只需要再连接一次就可以组成一个三角形了。又所有的边不能相交,因此每连接一条边,就相当于把整个平面上的点划分成了两个部分,在接下来的游戏中,只能单独在两部分里面进行,相当于将一个游戏划分成了两个游戏。因此当前状态x的sg函数值就是两个子游戏的Nim和了。
即:sg(x) = mex{ sg(i)^sg(x-i-2) }
这样复杂度很高。但是这道题目有规律,在大数据的范围下,会出现循环,循环长度为34,因此只需要小数据暴力,大
数据打表就哦了 .........SG函数-------->>>点击打开链接
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.
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, n 1, ..., n N.
Sum of all N <= 10 6.
1<=n i<=10 9.
Following are 2*T lines. For every two lines, the first line is N; the second line contains N numbers, n 1, ..., n N.
Sum of all N <= 10 6.
1<=n i<=10 9.
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
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
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,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,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,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,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
};
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,m,t;
int ans=0;
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%d",&m);
if(m<=150)
t=sg[m];
else
{
m-=150;
m%=34;
m+=150;
t=sg[m];
}
ans^=t;
}
if(ans==0)
printf("Dave\n");
else
printf("Carol\n");
}
return 0;
}
打表函数:
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<stdio.h>
#include<string.h>
using namespace std;
int vis[10011],sg[10011];
void init()
{
sg[0]=0;
sg[1]=0;
sg[2]=1;
for(int i=3; i<=10000; i++)//查找前300的
{
memset(vis,0,sizeof(vis));
for(int j=0; j<=(i-2); j++) //找到他前面的可以划分的进行划分标记
vis[sg[j]^sg[i-2-j]]=1;
for(int j=0;; j++) //找到前面未出现的第一个整数
if(!vis[j])
{
sg[i]=j;
break;
}
}
for(int i=0; i<=300; i++)
{
printf("%d ",sg[i]);
if(i%50==0)
printf("\n");
}
}
int main()
{
freopen("stdout.txt","w",stdout);
init();
}
说实话 会了也感觉不容易,第一次接触博弈看了好多博客,终于搞懂了。。。。