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.
 

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
查看评论
发表评论
* 以上用户言论仅仅代表其个人观点,不代表CSDN站点的观点或立场

【解题报告】HDU 4616 Game - 树形dp

/* dp[node][i][0]: node节点 在 消耗i陷阱时 并从该节点往下走(或者理解为还有能力往下走)的最大权值 dp[node][i][1]: node节点 在 消耗i陷...
  • x314542916
  • x314542916
  • 2013-07-29 11:05
  • 1505

NYOJ 题目23 取石子(一)。hdu 题目1846 Brave Game 巴什博奕(Bash Game)

取石子(一) 时间限制:3000 ms  |  内存限制:65535 KB 难度:2 描写叙述一天,TT在寝室闲着无聊,和同寝的人玩起了取石子游戏,而因为条件有限。他/她们是用旺...
  • u011282069
  • u011282069
  • 2013-08-25 18:06
  • 1074

hdu 1505 City Game(0和1 中的最大子矩阵)

City Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota...
  • u010709592
  • u010709592
  • 2014-01-23 00:51
  • 1551

HDU 5299 L - Circles Game 树上删边博弈

HDU 5299 L - Circles Game 树上删边博弈 There are n circles on a infinitely large table.With every two cir...
  • Mrx_Nh
  • Mrx_Nh
  • 2017-04-10 19:30
  • 128

hdu 5299 Circles Game

http://acm.hdu.edu.cn/showproblem.php?pid=5299题意:在坐标系中给出一些圆,这些圆可能相互包括和相离,如今两个人玩一个游戏,每一个人每次选择去掉一个圆,假设这...
  • yp_2013
  • yp_2013
  • 2016-02-13 13:28
  • 203

hdu 5299 Circles Game 2015 Multi-University Training Contest 1 计算几何+博弈SG函数 圆的扫描线

Circles Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Tot...
  • firenet1
  • firenet1
  • 2015-07-22 12:01
  • 896

hdu 5299 Circles Game 2015 Multi-University Training Contest 1

这一题開始以为是取石子游戏的Nim和。后来发现有一种case不满足,比方圆A包括B和C,但B和C在A内是相离的,玩家就无法仅删除两个圆。所以和随意取石子的Nim和就不一样了。 圆之间的包括关系能够转化...
  • yixin94
  • yixin94
  • 2015-08-16 21:56
  • 366

组合游戏(Circles Game,HDU 5299)

非常easy想到这是一个组合游戏。每一个子游戏都是一棵有根树上的游戏,最后的答案就是每一个子游戏SG值的Nim和。 有根树上的游戏就是给你一颗有根树,每次操作能够随便选取一个节点,并把这个节点所在的子树都删掉...
  • xl2015190026
  • xl2015190026
  • 2017-05-12 21:51
  • 663

HDU 5299 Circles Game

转化为树的删边游戏。

。。 Circles Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (J...

  • u011788531
  • u011788531
  • 2015-07-22 15:54
  • 1567

HDU 5299 Circles Game(树&博弈)

本文纯属原创。转载注明出处,谢谢。

传送门:http://acm.hdu.edu.cn/showproblem.php?

pid=5299 Time Limit: 2000/1000 MS (Java/...

  • u014705673
  • u014705673
  • 2015-07-27 14:39
  • 651
    个人资料
    • 訪问:715643次
    • 积分:11318
    • 等级:
    • 排名:第1575名
    • 原创:417篇
    • 转载:3篇
    • 译文:0篇
    • 评论:45条
    云中谁寄锦书来
【推广】 免费学中医,健康全家人
原文地址:https://www.cnblogs.com/cynchanpin/p/8270264.html