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. js判断手机浏览器操作系统和微信浏览器的方法

    做手机端的前端开发,少不了对手机平台的判断.如,对于app下载,就要判断在Android平台下就显示Android下载提示:在iOS平台下就显示iOS下载提示. 今天就为大家介绍一下用js判断手机客户 ...

  2. Cordova5 -- iOS实战(一)

      由于最近公司的项目要求用Cordova来进行开发,便开始了对Cordova的学习.由于本人之前也是做iOS开发,因此相关内容主要从iOS平台的角度来写.刚开始学习Cordova这个平台,希望以此总 ...

  3. 使用ibatis时 sql中 in 的参数赋值

    一.问题描述: 1.在使用ibatis执行下面的sql: update jc_jiesuan set doing_time = unix_timestamp(curdate()),doing_stat ...

  4. HDU 1175 连连看(BFS)

    连连看 Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submi ...

  5. libsdl中文输入法候选列表不显示解决方案

    libsdl输入中文时输入法不显示,将WM_IME_SETCONTEXT事件处理给注释即可. WM_IME_SETCONTEXT If the application draws the compos ...

  6. Linux网络

    netstat 查看网络状态 netstat: -r :显示路由表 -n: 以数字方式显示 -u: 显示UDP连接 -t :显示TCP连接 -l:显示监听状态的连接 -p: 显示监听指定套接字的进程的 ...

  7. jQuery学习 day01

    最近受某大牛指点(我不会说他姓范),了解了一下jQuery,据说很牛X,就了解了一下,第一天,分享给大家一些心得吧. 1.首先就是导入jQuery文件了,这里我是去jQuery官网下载的.(大家可以去 ...

  8. [C#]异步委托使用小计

    APM(=Asynchronous Programming Model(=异步编程模型)) 使用 IAsyncResult 设计模式的异步操作是通过名为 Begin操作名称 和 End操作名称 的两个 ...

  9. Sql中Rank排名函数

    A.对分区中的行进行排名 以下示例按照数量对指定清单位置的清单中的产品进行了排名. 结果集按 LocationID 分区并在逻辑上按 Quantity 排序. 注意,产品 494 和 495 具有相同 ...

  10. PHP - PHPExcel操作xls文件

    读取中文的xls.csv文件会有问题,网上找了下资料,发现PHPExcel类库好用,官网地址:http://phpexcel.codeplex.com/ 1.读取xls文件内容 <?php // ...