Circles Game

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 1427    Accepted Submission(s): 451

Problem Description
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
2
1
0 0 1
6
-100 0 90
-50 0 1
-20 0 1
100 0 90
47 0 1
23 0 1
 
Sample Output
Alice
Bob
 
Author
FZUACM
 
Source

显然圆的包括关系能够构成一片森林,然后问题就能够转化为:每一步能够删除森林的一棵树或者某树的一棵子树。不能删者输。

这样。问题就变成经典的树上删边游戏了。

树上删边游戏有一个非常重要的结论:叶子节点的SG值为0,中间节点的SG值为它的全部子节点的SG值加1后的异或和。(证明详见贾志豪论文《组合游戏略述——浅谈SG游戏的若干拓展及变形》)

如今。我们的主要问题就是怎样把圆的包括关系转化为森林。这里要用到圆的扫描线算法。首先对于每一个圆。创建两个时间点,一个进入一个离开。再对全部时间点从小到大排序。

然后逐个处理时间点。用set维护全部圆。每遇到一个进入时间。分情况讨论圆的位置关系。然后把这个圆插入set中。每遇到一个离开时间,从set中删除这个圆。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<set>
#define F(i,j,n) for(int i=j;i<=n;i++)
#define D(i,j,n) for(int i=j;i>=n;i--)
#define ll long long
#define maxn 20010
using namespace std;
int t,n,cnt,tt,tmp;
int head[maxn],fa[maxn];
struct cir{int x,y,r;}a[maxn];
struct edge_type{int next,to;}e[maxn*2];
struct bor
{
int x,f,id;
friend bool operator < (bor a,bor b)
{
if (a.x==b.x) return a.f<b.f;
return a.x<b.x;
}
}q[maxn*2];
double get_h(int id,int x,int opt)
{
return a[id].y+opt*sqrt(a[id].r*a[id].r-(a[id].x-x)*(a[id].x-x));
}
struct pos
{
int id,opt;
pos(int a=0,int b=0){id=a;opt=b;}
friend bool operator < (pos a,pos b)
{
if (a.id==b.id) return a.opt<b.opt;
return get_h(a.id,tmp,a.opt)<get_h(b.id,tmp,b.opt);
}
};
set<pos> s;
set<pos>::iterator it;
inline int read()
{
int x=0,f=1;char ch=getchar();
while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}
while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
inline void add_edge(int x,int y)
{
e[++cnt]=(edge_type){head[x],y};
head[x]=cnt;
fa[y]=x;
}
inline ll get(int x)
{
ll ret=0;
for(int i=head[x];i;i=e[i].next) ret^=get(e[i].to);
return ret+1;
}
int main()
{
t=read();
while (t--)
{
cnt=tt=0;
memset(fa,0,sizeof(fa));
memset(head,0,sizeof(head));
n=read();
F(i,1,n)
{
a[i].x=read();a[i].y=read();a[i].r=read();
q[++tt]=(bor){a[i].x-a[i].r,1,i};
q[++tt]=(bor){a[i].x+a[i].r,-1,i};
}
sort(q+1,q+tt+1);
F(i,1,tt)
{
if (q[i].f==1)
{
tmp=q[i].x;
it=s.lower_bound(pos(q[i].id,1));
if (it!=s.end())
{
if (it->opt==1) add_edge(it->id,q[i].id);
else if (fa[it->id]) add_edge(fa[it->id],q[i].id);
}
s.insert(pos(q[i].id,1));
s.insert(pos(q[i].id,-1));
}
else
{
s.erase(pos(q[i].id,1));
s.erase(pos(q[i].id,-1));
}
}
ll sum=0;
F(i,1,n) if (!fa[i]) sum=sum^get(i);
puts(sum?"Alice":"Bob");
}
}

1
0

hdu5299 Circles Game的更多相关文章

  1. [2015hdu多校联赛补题]hdu5299 Circles Game

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5299 题意: 在欧几里得平面上有n个圆,圆之间不会相交也不会相切,现在Alice和Bob玩游戏,两人轮 ...

  2. UVa247 Calling Circles

    Time Limit: 3000MS     64bit IO Format: %lld & %llu map存人名,floyd传递闭包,DFS查询. 输出答案的逗号后面还有个空格,被坑到了2 ...

  3. zw版【转发·台湾nvp系列Delphi例程】HALCON 3D Position Of Circles

    zw版[转发·台湾nvp系列Delphi例程]HALCON 3D Position Of Circles procedure TForm1.action();var ho_Image, ho_Elli ...

  4. UVa 247 Calling Circles【传递闭包】

    题意:给出n个人的m次电话,问最后构成多少个环,找出所有的环 自己想的是:用map来储存人名,每个人名映射成一个数字编号,再用并查集,求出有多少块连通块,输出 可是map不熟,写不出来,而且用并查集输 ...

  5. uva247 - Calling Circles(传递闭包+DFS)

    题意:两人相互打电话(直接或间接),则在一个电话圈.即a给b打电话,b给c打电话,则a给c间接打电话. 注意:1.注意标记.2.注意输出格式. #include<iostream> #in ...

  6. UVa 247 (传递闭包) Calling Circles

    题意: 有n个人m通电话,如果有两个人相互打电话(直接或间接)则在同一个电话圈里.输出所有电话圈的人的名单. 分析: 根据打电话的关系,可以建一个有向图,然后用Warshall算法求传递闭包. 最后输 ...

  7. 计数方法,博弈论(扫描线,树形SG):HDU 5299 Circles Game

    There are n circles on a infinitely large table.With every two circle, either one contains another o ...

  8. 数学计数原理(Pólya,高精度):SGU 294 He's Circles

      He's Circles He wrote n letters "X" and "E" in a circle. He thought that there ...

  9. UVA247- Calling Circles(有向图的强连通分量)

    题目链接 题意: 给定一张有向图.找出全部强连通分量,并输出. 思路:有向图的强连通分量用Tarjan算法,然后用map映射,便于输出,注意输出格式. 代码: #include <iostrea ...

随机推荐

  1. bug管理

    BUG提交规范 1.标题 2.步骤描述 ①.步骤使用序号编排 ②.在特定情况下发生的问题,还需提供准确的前提条件 ③.精准的描述bug产生的路径后,再描述现象 如: >打开客户端进行首页-> ...

  2. BZOJ2724 [Violet 6]蒲公英 分块

    原文链接https://www.cnblogs.com/zhouzhendong/p/BZOJ2724.html 题目传送门 - BZOJ2724 题意 求区间最小众数,强制在线. $n$ 个数,$m ...

  3. react部署

    https://www.cnblogs.com/jackson-zhangjiang/p/10095892.html React项目搭建与部署   React项目搭建与部署 一,介绍与需求 1.1,介 ...

  4. 找bug hhh

    http://oj.acm.zstu.edu.cn/JudgeOnline/problem.php?id=4434 没有用队列,疯狂找不到bug,后来发现很简单的判断时==n和m了,本来心花怒放,测试 ...

  5. 数据库相关--net start mysql 服务无法启动(win7系统)解决

    系统:win7 旗舰版 64位 MySQL:8.0.11 家里台式机上不久之前安装了MySQL,一段时间没碰过后,突然启动不了了(我有一头小毛驴,我从来也不骑,有一天我心血来潮骑它去赶集) 先是在系统 ...

  6. Typescript中抽象类与接口详细对比与应用场景介绍

    现如今,TS正在逐渐成为前端OO编程的不二之选,以下是我在学习过程中对抽象类和接口做的横向对比. 1. 抽象类当做父类,被继承.且抽象类的派生类的构造函数中必须调用super():接口可以当做“子类” ...

  7. JDK 1.6 HashMap 源码分析

    前言 ​ 前段时间研究了一下JDK 1.6 的 HashMap 源码,把部份重要的方法分析一下,当然HashMap中还有一些值得研究得就交给读者了,如有不正确之处还望留言指正. 准备 ​ 需要熟悉数组 ...

  8. mybatis查询语句的背后之参数解析

    转载请注明出处... 一.前言 通过前面我们也知道,通过getMapper方式来进行查询,最后会通过mapperMehod类,对接口中传来的参数也会在这个类里面进行一个解析,随后就传到对应位置,与sq ...

  9. 表达式语言引擎:Apache Commons JEXL 2.1 发布

    http://www.linuxde.net/2011/12/4348.html Commons JEXL 2.1 发布了,该版本和 2.0.1 是二进制兼容的,但源码不兼容,因为新增了两个接口: o ...

  10. PAT (Advanced Level) Practise 1004 解题报告

    GitHub markdownPDF 问题描述 解题思路 代码 提交记录 问题描述 Counting Leaves (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 1600 ...