博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
计数方法,博弈论(扫描线,树形SG):HDU 5299 Circles Game
阅读量:5101 次
发布时间:2019-06-13

本文共 2860 字,大约阅读时间需要 9 分钟。

There are n circles on a infinitely large table.With every two circle, either one contains another or isolates from the other.They are never crossed nor tangent.
Alice and Bob are playing a game concerning these circles.They take turn to play,Alice goes first:
1、Pick out a certain circle A,then delete A and every circle that is inside of A.
2、Failling to find a deletable circle within one round will lost the game.
Now,Alice and Bob are both smart guys,who will win the game,output the winner's name.
 

Input

The first line include a positive integer T<=20,indicating the total group number of the statistic.
As for the following T groups of statistic,the first line of every group must include a positive integer n to define the number of the circles.
And the following lines,each line consists of 3 integers x,y and r,stating the coordinate of the circle center and radius of the circle respectively.
n≤20000,|x|≤20000,|y|≤20000,r≤20000。
 

Output

If Alice won,output “Alice”,else output “Bob”
 

Sample Input

210 0 16-100 0 90-50 0 1-20 0 1100 0 9047 0 123 0 1

Sample Output

AliceBob   这道题目可以说是模板题……   就是那个SG函数的求法貌似是结论,我不会证明。
1 #include 
2 #include
3 #include
4 #include
5 #include
6 #include
7 using namespace std; 8 const int N=20010,M=40010; 9 int cnt,fir[N],to[N],nxt[N];10 void addedge(int a,int b){11 nxt[++cnt]=fir[a];12 to[fir[a]=cnt]=b;13 }14 int sqr(int x){ return x*x;}15 int tmp;16 struct Circle{17 int x,y,r;18 Circle(int _=0,int __=0,int ___=0){x=_;y=__;r=___;}19 }c[N];20 21 struct Point{22 int x,id,tp;23 Point(int _=0,int __=0,int ___=0){x=_;id=__;tp=___;}24 friend bool operator<(Point a,Point b){25 double x=c[a.id].y+a.tp*sqrt(sqr(c[a.id].r)-sqr(tmp-c[a.id].x));26 double y=c[b.id].y+b.tp*sqrt(sqr(c[b.id].r)-sqr(tmp-c[b.id].x));27 if(x!=y)return x
s;set
::iterator it;33 34 int fa[N],sg[N];35 int DFS(int x){36 sg[x]=0;37 for(int i=fir[x];i;i=nxt[i])38 sg[x]^=DFS(to[i])+1;39 return sg[x];40 }41 42 void Init(){43 memset(fir,0,sizeof(fir));44 cnt=0;45 }46 int T,n;47 int main(){48 scanf("%d",&T);49 while(T--){50 Init();scanf("%d",&n);51 for(int i=1;i<=n;i++){52 scanf("%d%d%d",&c[i].x,&c[i].y,&c[i].r);53 st[2*i-1]=Point(c[i].x-c[i].r,i,-1);54 st[2*i]=Point(c[i].x+c[i].r,i,1);55 }56 sort(st+1,st+2*n+1,cmp);57 for(int i=1;i<=2*n;i++){58 Point x=st[i];tmp=x.x;59 if(x.tp==-1){60 it=s.upper_bound(Point(0,x.id,1));61 if(it==s.end())addedge(fa[x.id]=0,x.id);62 else{63 Point y=*it;64 if(y.tp==1)65 addedge(fa[x.id]=y.id,x.id);66 else67 addedge(fa[x.id]=fa[y.id],x.id);68 }69 s.insert(Point(0,x.id,1));70 s.insert(Point(0,x.id,-1));71 }72 else{73 s.erase(Point(0,x.id,1));74 s.erase(Point(0,x.id,-1));75 }76 }77 printf(DFS(0)?"Alice\n":"Bob\n"); 78 }79 return 0;80 }

 

转载于:https://www.cnblogs.com/TenderRun/p/6005774.html

你可能感兴趣的文章
ResolveUrl的用法
查看>>
Linux内核态、用户态简介与IntelCPU特权级别--Ring0-3
查看>>
第23月第24天 git命令 .git-credentials git rm --cached git stash clear
查看>>
java SE :标准输入/输出
查看>>
一些方便系统诊断的bash函数
查看>>
【转载】基于vw等viewport视区相对单位的响应式排版和布局
查看>>
<转>关于MFC的多线程类 CSemaphore,CMutex,CCriticalSection,CEvent
查看>>
jquery中ajax返回值无法传递到上层函数
查看>>
css3之transform-origin
查看>>
[转]JavaScript快速检测浏览器对CSS3特性的支持
查看>>
Master选举原理
查看>>
[ JAVA编程 ] double类型计算精度丢失问题及解决方法
查看>>
小别离
查看>>
微信小程序-发起 HTTPS 请求
查看>>
WPF动画设置1(转)
查看>>
backgound-attachment属性学习
查看>>
个人作业——关于K米的产品案例分析
查看>>
基于node/mongo的App Docker化测试环境搭建
查看>>
java web 中base64传输的坑
查看>>
java 中的线程(一)
查看>>