HDU 4664 Triangulation(2013多校6 1010题,博弈)
2013-08-08 19:31
344 查看
Triangulation
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 96 Accepted Submission(s): 29
[align=left]Problem Description[/align]
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.
[align=left]Input[/align]
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.
[align=left]Output[/align]
T lines. If Carol wins the corresponding game, print 'Carol' (without quotes;) otherwise, print 'Dave' (without quotes.)
[align=left]Sample Input[/align]
2
1
2
2
2 2
[align=left]Sample Output[/align]
Carol
Dave
[align=left]Source[/align]
2013 Multi-University Training Contest 6
[align=left]Recommend[/align]
zhuyuanchen520
这题一开始看错题目意思了。
导致连SG函数转移都写不出来。
其实这题看懂了就很好搞了。
每次加边,不能形成三角形,所以肯定不加共点的边,否则就是自杀。
x个点,转移后相当于 i , x-i-2 .加的那两个点去掉了。
SG函数打表以后,很明显是要找规律。
发现周期是34.
而且周期要到后面才有周期。
所以前面打表,后面利用周期。
可以参考下oeis,发现这个是经典的问题。Sprague-Grundy values for Dawson's Chess
http://oeis.org/search?q=0%2C1%2C1%2C2%2C0%2C3%2C1%2C1%2C0%2C3%2C3%2C2%2C2%2C4%2C0%2C5%2C2%2C2%2C3%2C3%2C0&sort=&language=english&go=Search
Has period 34 with the only exceptions at n=0, 14, 16, 17, 31, 34 and 51.
然后胡搞下就过了
/* * Author: kuangbin * Created Time: 2013/8/8 11:54:23 * File Name: 1010.cpp */ #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <algorithm> #include <string> #include <vector> #include <stack> #include <queue> #include <set> #include <time.h> using namespace std; const int MAXN = 100010; int sg[MAXN]; bool vis[MAXN]; int mex(int x) { if(sg[x]!=-1)return sg[x]; if(x == 0)return sg[x] = 0; if(x == 1)return sg[x] = 0; if(x == 2)return sg[x] = 1; if(x == 3)return sg[x] = 1; memset(vis,false,sizeof(vis)); for(int i = 0;i < x-1;i++) vis[mex(i)^mex(x-i-2)] = true; for(int i = 0;;i++) if(!vis[i]) return sg[x] = i; } int SG(int x) { if(x <= 200)return sg[x]; else { x %= 34; x += 4*34; return sg[x]; } } int main() { //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); memset(sg,-1,sizeof(sg)); for(int i = 0;i <= 1000;i++) { sg[i] = mex(i); } int T; int n; int a; scanf("%d",&T); while(T--) { scanf("%d",&n); int sum = 0; for(int i = 0;i < n;i++) { scanf("%d",&a); sum ^= SG(a); } if(sum)printf("Carol\n"); else printf("Dave\n"); } return 0; }
相关文章推荐
- hdu 4664 Triangulation/杭电多校2013第六场1010, SG定理+找规律
- 2013 多校第六场 hdu 4664 Triangulation(SG问题)
- hdu 4664 Triangulation(博弈)
- HDU 4630 No Pain No Game(2013多校3 1010题 离线处理+树状数组求最值)
- HDU 6105 (2017 多校训练赛6 1010)Gameia(博弈)
- 2013多校联合4 1010 K-string (hdu 4641)
- HDU-4664 Triangulation 博弈,SG函数找规律
- HDU 4675 GCD of Sequence (2013多校7 1010题 数学题)
- HDU-4664 Triangulation(博弈SG打表+类似凸包性质)
- 2013多校联合3 1010 No Pain No Game(hdu 4630)
- HDU 4642 Fliping game (2013多校4 1011 简单博弈)
- 2013 多校第九场 hdu 4690 EBCDIC(打表)
- HDU 4639 Hehe (2013多校4 1008 水题)
- 2013 多校联合4 1011 Fliping game (hdu 4642)
- 2013 多校联合4 1007 Group(hdu 4638)
- HDU 4633 Who's Aunt Zhang (2013多校4 1002 polya计数)
- 2013 多校第九场 hdu 4705 Y(枚举 + 树上的计数)
- 2013 多校第九场 hdu 4704 Sum(2的幂次方取模)
- HDU 4643 GSM 简单计算几何 (2013多校联合)
- hdu 4617 2013多校联合训练第二场weapon简单的计算几何