HDU-4664 Triangulation 博弈,SG函数找规律

时间:2020-12-29 21:17:44

  题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4664

  题意:一个平面上有n个点(一个凸多边形的顶点),每次可以连接一个平面上的两个点(不能和已经连接的边相交),如果平面上已经出现了一个三角形,则不能在这个平面上继续连接边了。

  首先在最优情况下,优先考虑的是一个点不连两条直线,否则就直接输了。因此一个n个点的局面连了一条直线后,分为了两个子游戏,i个点和n-i-2个点,则sg[n]=mex(sg[n]^sg[n-i-2])。然后打表找规律,发现大于n大于68后就是34的循环节了。

 //STATUS:C++_AC_203MS_428KB
#include <functional>
#include <algorithm>
#include <iostream>
//#include <ext/rope>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
#pragma comment(linker,"/STACK:102400000,102400000")
//using namespace __gnu_cxx;
//define
#define pii pair<int,int>
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define PI acos(-1.0)
//typedef
typedef __int64 LL;
typedef unsigned __int64 ULL;
//const
const int N=;
const int INF=0x3f3f3f3f;
const LL MOD=,STA=;
const LL LNF=1LL<<;
const double EPS=1e-;
const double OO=1e30;
const int dx[]={-,,,};
const int dy[]={,,,-};
const int day[]={,,,,,,,,,,,,};
//Daily Use ...
inline int sign(double x){return (x>EPS)-(x<-EPS);}
template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> inline T lcm(T a,T b,T d){return a/d*b;}
template<class T> inline T Min(T a,T b){return a<b?a:b;}
template<class T> inline T Max(T a,T b){return a>b?a:b;}
template<class T> inline T Min(T a,T b,T c){return min(min(a, b),c);}
template<class T> inline T Max(T a,T b,T c){return max(max(a, b),c);}
template<class T> inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));}
template<class T> inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));}
//End int sg[N];
int vis[N];
int T,n; void Init()
{
int i,j;
sg[]=sg[]=;
int n=;
for(i=;i<n;i++){
mem(vis,);
for(j=;i-j->=;j++)vis[sg[j]^sg[i-j-]]=;
for(j=;vis[j];j++);
sg[i]=j;
}
} inline int getsg(int a)
{
return a<=?sg[a]:sg[+(a%?a%:)];
} int main(){
// freopen("in.txt","r",stdin);
int i,j,sg,a;
scanf("%d",&T);
Init();
while(T--)
{
scanf("%d",&n);
sg=;
while(n--){
scanf("%d",&a);
sg=sg^getsg(a);
} printf("%s\n",sg?"Carol":"Dave");
}
return ;
}