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
  这道题目可以说是模板题……
  就是那个SG函数的求法貌似是结论,我不会证明。
 #include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <set>
using namespace std;
const int N=,M=;
int cnt,fir[N],to[N],nxt[N];
void addedge(int a,int b){
nxt[++cnt]=fir[a];
to[fir[a]=cnt]=b;
}
int sqr(int x){return x*x;}
int tmp;
struct Circle{
int x,y,r;
Circle(int _=,int __=,int ___=){x=_;y=__;r=___;}
}c[N]; struct Point{
int x,id,tp;
Point(int _=,int __=,int ___=){x=_;id=__;tp=___;}
friend bool operator<(Point a,Point b){
double x=c[a.id].y+a.tp*sqrt(sqr(c[a.id].r)-sqr(tmp-c[a.id].x));
double y=c[b.id].y+b.tp*sqrt(sqr(c[b.id].r)-sqr(tmp-c[b.id].x));
if(x!=y)return x<y;return a.tp<b.tp;
}
}st[M]; bool cmp(Point a,Point b){return a.x<b.x;}
set<Point>s;set<Point>::iterator it; int fa[N],sg[N];
int DFS(int x){
sg[x]=;
for(int i=fir[x];i;i=nxt[i])
sg[x]^=DFS(to[i])+;
return sg[x];
} void Init(){
memset(fir,,sizeof(fir));
cnt=;
}
int T,n;
int main(){
scanf("%d",&T);
while(T--){
Init();scanf("%d",&n);
for(int i=;i<=n;i++){
scanf("%d%d%d",&c[i].x,&c[i].y,&c[i].r);
st[*i-]=Point(c[i].x-c[i].r,i,-);
st[*i]=Point(c[i].x+c[i].r,i,);
}
sort(st+,st+*n+,cmp);
for(int i=;i<=*n;i++){
Point x=st[i];tmp=x.x;
if(x.tp==-){
it=s.upper_bound(Point(,x.id,));
if(it==s.end())addedge(fa[x.id]=,x.id);
else{
Point y=*it;
if(y.tp==)
addedge(fa[x.id]=y.id,x.id);
else
addedge(fa[x.id]=fa[y.id],x.id);
}
s.insert(Point(,x.id,));
s.insert(Point(,x.id,-));
}
else{
s.erase(Point(,x.id,));
s.erase(Point(,x.id,-));
}
}
printf(DFS()?"Alice\n":"Bob\n");
}
return ;
}

计数方法,博弈论(扫描线,树形SG):HDU 5299 Circles Game的更多相关文章

  1. HDU 5299 Circles Game

    HDU 5299 思路: 圆扫描线+树上删边博弈 圆扫描线有以下四种情况,用set维护扫描线与圆的交点,重载小于号 代码: #pragma GCC optimize(2) #pragma GCC op ...

  2. HDU 5299 Circles Game 博弈论 暴力

    Circles Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5299 Description There are n circles on ...

  3. 计数方法(扫描线):JLOI 2016 圆的异或并

    Description 在平面直角坐标系中给定N个圆.已知这些圆两两没有交点,即两圆的关系只存在相离和包含.求这些圆的异或面 积并.异或面积并为:当一片区域在奇数个圆内则计算其面积,当一片区域在偶数个 ...

  4. HDU 5299 圆扫描线 + 树上删边

    几何+博弈的简单组合技 给出n个圆,有包含关系,以这个关系做游戏,每次操作可以选择把一个圆及它内部的圆全部删除,不能操作者输. 圆的包含关系显然可以看做是树型结构,所以也就是树上删边的游戏. 而找圆的 ...

  5. 【spring data jpa】jpa中使用count计数方法

    spring data jpa中使用count计数方法很简单 直接在dao层写方法即可 int countByUidAndTenementId(String parentUid, String ten ...

  6. 【概率论】1-2:计数方法(Counting Methods)

    title: [概率论]1-2:计数方法(Counting Methods) categories: Mathematic Probability keywords: Counting Methods ...

  7. fwt优化+树形DP HDU 5909

    //fwt优化+树形DP HDU 5909 //见官方题解 // BestCoder Round #88 http://bestcoder.hdu.edu.cn/ #include <bits/ ...

  8. 博弈论进阶之SG函数

    SG函数 个人理解:SG函数是人们在研究博弈论的道路上迈出的重要一步,它把许多杂乱无章的博弈游戏通过某种规则结合在了一起,使得一类普遍的博弈问题得到了解决. 从SG函数开始,我们不再是单纯的同过找规律 ...

  9. 博弈论基础之sg函数与nim

    在算法竞赛中,博弈论题目往往是以icg.通俗的说就是两人交替操作,每步都各自合法,合法性与选手无关,只与游戏有关.往往我们需要求解在某一个游戏或几个游戏中的某个状态下,先手或后手谁会胜利的问题.就比如 ...

随机推荐

  1. mysql笔记之集群

    1.主从配置 #主从都要加入以下配置如下 [mysqld] log-bin=mysql-bin #主从要不一样 server-id=222 #在主上建立一个用户给从的用 GRANT REPLICATI ...

  2. 国庆第六日(2014年10月6日11:51:15),node-webkit,理财产品

    (1)node-webkit:一篇很好的入门文章.入门.系列. 在window下的打包和运行.大漠的一篇讲解文章 . (2)lighttable: 官网. (3)现在的理财产品,雨后春笋般冒出:宝点网 ...

  3. can't find -lsocket的解决办法

    在UNIX/LINUX当中是不存在libsocket的.传说中,socket的功能库是放在libc当中的,所以如果需要连接的话修改成-lc就可以了.

  4. 绑定本地Service并与之通信

    绑定Service需要调用 public boolean bindService (Intent service, ServiceConnection conn, int flags): 传入一个Se ...

  5. 完整的 AJAX 写法(支持多浏览器)

    代码如下: <script type="text/javascript"> var xmlhttp; function Submit() { //1.创建 XMLHtt ...

  6. linux 文件类型

    文件类型 1)windows中是以文件的扩展名来区分文件类型的 2)LINUX中文件扩展名和文件类型没有关系. 3)为了容易区分和兼容用户使用windows的习惯,我们也经常扩展名,但是在LINUX系 ...

  7. 跨域、sql注入、xss攻击

    这几天遇到这三个问题,现在简单的记录下来. 1.跨域 如我服务器的域名是www.test1.com,我在另一个服务器www.test2.com通过ajax访问www.test1.com的数据时,就引起 ...

  8. php中文编码

    header("Content-type: text/html; charset=utf-8"); header('Location: http://www.example.com ...

  9. An easy way to syncTime using C#

    /* * Created by SharpDevelop. * User: Administrator * Date: 2013/10/23 * Time: 8:57 * author zibet * ...

  10. Educational Codeforces Round 6 D. Professor GukiZ and Two Arrays

    Professor GukiZ and Two Arrays 题意:两个长度在2000的-1e9~1e9的两个序列a,b(无序);要你最多两次交换元素,使得交换元素后两序列和的差值的绝对值最小:输出这 ...