HDU-4664 Triangulation 博弈,SG函数找规律
题目链接: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 ;
}
HDU-4664 Triangulation 博弈,SG函数找规律的更多相关文章
- HDU 4664 Triangulation(SG函数)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4664 题意:给出一个n个点的凸包(不存在三点共线).每次可以选择两个点连线,但是任意两条线只能在顶点处 ...
- BZOJ 1228 E&G(sg函数+找规律)
把一对石子堆看出一个子游戏.打出子游戏的sg表找规律.. 这个规律我是一定找不出来的... 对于i,j,如果 (i-1)%pow(2,k+1) < pow(2,k) (j-1)%pow(2,k+ ...
- HDU 1517 A Multiplication Game (SG函数找规律)
题意:两个玩家玩一个游戏,从 p = 1,开始,然后依次轮流选择一个2 - 9的数乘以 p,问你谁先凑够 p >= n. 析:找规律,我先打了一下SG函数的表,然后就找到规律了 我找到的是: 1 ...
- hdu 3032(博弈sg函数)
题意:与原来基本的尼姆博弈不同的是,可以将一堆石子分成两堆石子也算一步操作,其它的都是一样的. 分析:由于石子的堆数和每一堆石子的数量都很大,所以肯定不能用搜索去求sg函数,现在我们只能通过找规律的办 ...
- 51nod_1661: 黑板上的游戏(sg函数 找规律)
题目链接 先打一个sg函数的表,找找规律,发现sg函数可以递归求解 打表代码如下 #include<bits/stdc++.h> using namespace std; typedef ...
- 51nod 1661: 黑板上的游戏(sg函数 找规律)
题目链接 先打一个sg函数的表,找找规律,发现sg函数可以递归求解 打表代码如下 #include<bits/stdc++.h> using namespace std; typedef ...
- Light OJ 1296 - Again Stone Game (博弈sg函数递推)
F - Again Stone Game Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu ...
- HDU 5795 A Simple Nim (博弈 打表找规律)
A Simple Nim 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5795 Description Two players take turns ...
- S-Nim HDU 1536 博弈 sg函数
S-Nim HDU 1536 博弈 sg函数 题意 首先输入K,表示一个集合的大小,之后输入集合,表示对于这对石子只能去这个集合中的元素的个数,之后输入 一个m表示接下来对于这个集合要进行m次询问,之 ...
随机推荐
- POJ1905Expanding Rods(二分)
http://poj.org/problem?id=1905 题意 :在两堵实心墙中间有一根杆,长度为L,然后给它加热,温度是n,则两墙之间的杆会弯曲,长度会变为L'=(1+n*C)*L,求前后两个状 ...
- CodeForces 300A Array
http://codeforces.com/problemset/problem/300/A 题意 :给你n个数字,让你分成3组,第一组各个数之积要小于0,第二组要大于0,第三组要等于0,符合要求的答 ...
- saltstack远程操作WINDOWS的POWERSHELL脚本
这个东东,花了两天来查找资料和测试,终于算是搞定.作记录: 直接在MASTER上执行的命令: salt '*' cmd.script salt://scripts/windows_task.ps1 a ...
- 获取Android系统时间
目的: 输入 2014-09-09 14:02:03 输出 等待:1小时20分 注意: HH:mm:ss 为获取手机 24小时格式的时间 15:03 hh:mm:ss 为12小时模式的时 ...
- linux bash_profile和.bashrc区别
经常在一些技术类的文章中提到修改bash_profile和.bashrc这两个文件,也算是使用频率比较高的两个文件吧,但实现同样一个功能,有的教程里说修改bash_profile这个文件,有的教程里却 ...
- adobe 蛋疼的套装, 想安装一个Flash Professional CS6,标准版还没有...
产品比较 查看内容 查看各 Creative Suite 6 版本的组件. Design Standard Design & Web Premium Production Premium Ma ...
- seek和tell的用法--获取文件内容大小(字节)
/*获取文件中存取的数据内容的大小(字节数) ellg() 和 tellp() 这两个成员函数不用传入参数,返回pos_type 类型的值(根据ANSI-C++ 标准) ,就是一个整数,代表当前get ...
- Android:控件Spinner实现下拉列表
在Web开发中,HTML提供了下拉列表的实现,就是使用<select>元素实现一个下拉列表,在其中每个下拉列表项使用<option>表示即可.这是在Web开发中一个必不可少的交 ...
- IntelliJ idea 中使用Git
1.要使用GitHub,首先你需要下载一个Git(地址:http://windows.github.com/)这里使用的是for Windows,然后安装完成会得到如下的一个目录:
- Frequent values && Ping pong
Frequent values 题意是不同颜色区间首尾相接,询问一个区间内同色区间的最长长度. 网上流行的做法,包括翻出来之前POJ的代码也是RMQ做法,对于序列上的每个数,记录该数向左和向右延续的最 ...