HDU4664 Triangulation sg函数
来源:互联网 发布:如何提高免疫力 知乎 编辑:程序博客网 时间:2024/04/29 03:16
题目链接:HDU4664
Triangulation
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 783 Accepted Submission(s): 312
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.
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.
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
21222 2
Sample Output
CarolDave
按照要求构建sg函数即可,每次连线都不可以相交,所以每连一条线就相当于把平面一分为二为2个字问题,打表求sg函数即可。由于数据量比较大,所以找规律,发现后面是有循环节的,求循环节即可。
//// main.cpp// HDU4664//// Created by teddywang on 2016/9/6.// Copyright © 2016年 teddywang. All rights reserved.//#include <iostream>#include<cstdio>#include<algorithm>#include<cstring>using namespace std;int T,n;int sg[250];int mex(int x){ if(sg[x]>=0) return sg[x]; int vis[40]; memset(vis,0,sizeof(vis)); for(int i=0;i<x-1;i++) { sg[i]=mex(i); sg[x-i-2]=mex(x-i-2); vis[sg[i]^sg[x-i-2]]=1; } for(int i=0;;i++) { if(!vis[i]) return i; }}void getsg(){ memset(sg, -1, sizeof(sg)); sg[0]=0; sg[1]=0; sg[2]=1; sg[3]=1; for(int i=0;i<230;i++) { sg[i+4]=mex(i+4); }}int SG(int x){ if(x<200) return sg[x]; else{ x%=34; return sg[x+4*34]; }}int main(){ getsg(); //for(int i=0;i<200;i++) // cout<<sg[i]<<endl; cin>>T; while(T--) { scanf("%d",&n); int ans=0; for(int i=0;i<n;i++) { int num; scanf("%d",&num); ans^=SG(num); } if(ans==0) printf("Dave\n"); else printf("Carol\n"); }}
0 0
- HDU4664 Triangulation sg函数
- SG函数 hdu 4664 Triangulation
- HDU 4664 Triangulation-SG函数
- hdu4664 Triangulation 多校第六场
- HDU 4664 Triangulation (SG函数,打表找规律)
- HDU4664
- hdu - 4664 - Triangulation(博弈SG)
- hdu 4664 Triangulation(博弈论 sg找规律打表)
- sg函数
- SG函数
- SG函数
- SG函数
- SG函数
- SG函数
- SG函数
- SG函数
- SG函数
- SG函数
- SSH Tunnel 一般场景用法
- 【PM】项目进度管理不利该怎么办
- Android17--Android之常见问题库
- listview的封装使用
- uva 12230
- HDU4664 Triangulation sg函数
- 【egret】Tween类
- Android Studio的自动提示功能忽略大小写敏感
- php 计算出一年中每周的周一日期
- 15 获取运行时的style 属性值
- codeforces 618D. Hamiltonian Spanning Tree
- C++中函数返回临时对象和本地对象的区别
- 数组
- 项目实战--项目介绍