hdu5299 Circles Game
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.
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。
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
顯然圓的包括關(guān)系能夠構(gòu)成一片森林,然后問題就能夠轉(zhuǎn)化為:每一步能夠刪除森林的一棵樹或者某樹的一棵子樹。不能刪者輸。
這樣。問題就變成經(jīng)典的樹上刪邊游戲了。
樹上刪邊游戲有一個非常重要的結(jié)論:葉子節(jié)點的SG值為0,中間節(jié)點的SG值為它的全部子節(jié)點的SG值加1后的異或和。(證明詳見賈志豪論文《組合游戲略述——淺談SG游戲的若干拓展及變形》)
如今。我們的主要問題就是怎樣把圓的包括關(guān)系轉(zhuǎn)化為森林。這里要用到圓的掃描線算法。首先對于每一個圓。創(chuàng)建兩個時間點,一個進(jìn)入一個離開。再對全部時間點從小到大排序。
然后逐個處理時間點。用set維護(hù)全部圓。每遇到一個進(jìn)入時間。分情況討論圓的位置關(guān)系。然后把這個圓插入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
查看評論
發(fā)表評論
* 以上用戶言論僅僅代表其個人觀點,不代表CSDN站點的觀點或立場
- 個人資料
- 訪問:715643次
- 積分:11318
- 等級:
- 排名:第1575名
- 原創(chuàng):417篇
- 轉(zhuǎn)載:3篇
- 譯文:0篇
- 評論:45條
- 云中誰寄錦書來
-
QQ:1045980567
微博:郭仲康A(chǔ)aron
- 奔跑在光陰里的同行者
- 文章搜索
- 文章分類
- 追(4)
- 總結(jié)(5)
- 好題(148)
- 二分(16)
- 三分(2)
- 搜索(19)
- 數(shù)學(xué)(16)
- 模擬(7)
- 倍增(8)
- 貪心(13)
- 分塊(11)
- 分治(7)
- 凸包(8)
- 虛樹(1)
- LCA(2)
- RMQ(3)
- KMP(7)
- FFT(5)
- NTT(3)
- Hash(8)
- Floyd(4)
- Treap(11)
- Splay(11)
- 網(wǎng)絡(luò)流(38)
- 線段樹(44)
- 高精度(3)
- 并查集(7)
- 單調(diào)棧(5)
- 生成樹(8)
- 離散化(6)
- 前綴和(5)
- 劃分樹(1)
- 樹套樹(4)
- 博弈論(2)
- 掃描線(3)
- 線性基(3)
- 二分圖(2)
- 可并堆(4)
- Trie樹(9)
- Tarjan(3)
- DFS序(8)
- 數(shù)位DP(4)
- 概率DP(7)
- 樹形DP(6)
- 狀壓DP(5)
- 拓?fù)渑判?/a>(5)
- 動態(tài)規(guī)劃(78)
- 哈夫曼樹(1)
- 優(yōu)先隊列(7)
- 最短路徑(15)
- 樹狀數(shù)組(20)
- 單調(diào)隊列(4)
- 線性規(guī)劃(2)
- 后綴數(shù)組(6)
- 樹鏈剖分(12)
- 莫隊算法(4)
- 容斥原理(13)
- 分?jǐn)?shù)規(guī)劃(1)
- 矩陣乘法(3)
- 高斯消元(4)
- 旋轉(zhuǎn)卡殼(2)
- 半平面交(5)
- 最小割樹(1)
- 歐拉回路(1)
- C++語言(4)
- K-D Tree(2)
- CDQ分治(6)
- AC自己主動機(7)
- prufer編碼(1)
- manacher(5)
- 回文自己主動機(1)
- 啟示式合并(3)
- 樹的點分治(4)
- 后綴自己主動機(5)
- 隨機增量法(2)
- 最小圓覆蓋(2)
- 最小表示法(1)
- link-cut tree(3)
- 斜率優(yōu)化DP(9)
- Simpson積分(1)
- 計算幾何基礎(chǔ)(3)
- 弦圖的點染色(1)
- 莫比烏斯反演(8)
- 差分約束系統(tǒng)(1)
- 切比雪夫距離(1)
- 平面圖轉(zhuǎn)對偶圖(2)
- 最大權(quán)閉合子圖(2)
- Matrix-Tree定理(1)
- Pollard-Rho算法(1)
- 可持久化數(shù)據(jù)結(jié)構(gòu)(15)
-
閱讀排行
- bzoj3998【TJOI2015】弦論(5577)
- bzoj3295【CQOI2011】動態(tài)逆序?qū)?/a>(4950)
- bzoj3270 博物館(4844)
- bzoj2683簡單題(4613)
- bzoj2318 Spoj4060 game with probability Problem(4450)
- bzoj3223 Tyvj1729 文藝平衡樹(4416)
- bzoj1415【NOI2005】聰聰和可可(4300)
- bzoj1176【Balkan2007】Mokia(4202)
- bzoj3143【HNOI2013】游走(4190)
- bzoj1492【NOI2007】貨幣兌換Cash(4124)
posted on 2018-01-11 19:41 cynchanpin 閱讀(397) 評論(0) 收藏 舉報
浙公網(wǎng)安備 33010602011771號