HDOJ 5299 Circles Game 圆嵌套+树上SG
将全部的圆化成树,然后就能够转化成树上的删边博弈问题....
Circles Game
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 881 Accepted Submission(s): 255
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.
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。
2
1
0 0 1
6
-100 0 90
-50 0 1
-20 0 1
100 0 90
47 0 1
23 0 1
Alice
Bob
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector> using namespace std; #pragma comment(linker, "/STACK:1024000000,1024000000") const int maxn=20200; int n;
struct Circle
{
int x,y,r;
bool operator<(const Circle& cir) const
{
return r>cir.r;
}
}circle[maxn]; double dist(int a,int b)
{
return sqrt((circle[a].x-circle[b].x)*(circle[a].x-circle[b].x)
+(circle[a].y-circle[b].y)*(circle[a].y-circle[b].y));
} vector<int> edge[maxn]; void Link(int u,int x)
{
bool fg=true;
for(int i=0,sz=edge[u].size();i<sz;i++)
{
int v=edge[u][i];
double dd=dist(x,v);
if(dd+circle[x].r>circle[v].r) continue;
fg=false;
Link(v,x);
return ;
}
if(fg) edge[u].push_back(x);
} int dp[maxn]; void dfs(int u)
{
int ret=-1;
for(int i=0,sz=edge[u].size();i<sz;i++)
{
int v=edge[u][i];
dfs(v);
if(ret==-1) ret=dp[v]+1;
else ret^=dp[v]+1;
}
if(ret==-1) ret=0;
dp[u]=ret;
} int main()
{
int T_T;
scanf("%d",&T_T);
while(T_T--)
{
scanf("%d",&n);
for(int i=1,x,y,r;i<=n;i++)
{
scanf("%d%d%d",&x,&y,&r);
//circle[i]=(Circle){x,y,r};
circle[i].x=x;
circle[i].y=y;
circle[i].r=r;
edge[i].clear();
}
edge[0].clear();
sort(circle+1,circle+1+n);
for(int i=1;i<=n;i++)
{
Link(0,i); dp[i]=0;
}
dfs(0);
if(dp[0]==0) puts("Bob");
else puts("Alice");
}
return 0;
}
HDOJ 5299 Circles Game 圆嵌套+树上SG的更多相关文章
- HDU 5299 Circles Game
HDU 5299 思路: 圆扫描线+树上删边博弈 圆扫描线有以下四种情况,用set维护扫描线与圆的交点,重载小于号 代码: #pragma GCC optimize(2) #pragma GCC op ...
- [SPOJ-CIRU]The area of the union of circles/[BZOJ2178]圆的面积并
[SPOJ-CIRU]The area of the union of circles/[BZOJ2178]圆的面积并 题目大意: 求\(n(n\le1000)\)个圆的面积并. 思路: 对于一个\( ...
- 【题解】CIRU - The area of the union of circles [SP8073] \ 圆的面积并 [Bzoj2178]
[题解]CIRU - The area of the union of circles [SP8073] \ 圆的面积并 [Bzoj2178] 传送门: \(\text{CIRU - The area ...
- 计数方法,博弈论(扫描线,树形SG):HDU 5299 Circles Game
There are n circles on a infinitely large table.With every two circle, either one contains another o ...
- HDU 5299 Circles Game 博弈论 暴力
Circles Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5299 Description There are n circles on ...
- hdu 3094 A tree game 树上sg
A tree game Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Prob ...
- 【UVALive 4642】Malfatti Circles(圆,二分)
题 给定三角形,求三个两两相切且与三角形的一条边相切的圆的半径. 二分一个半径,可以得出另外两个半径,需要推一推公式(太久了,我忘记了) #include<cstdio> #include ...
- 【百题留念】hdoj 1524 A Chess Game(dfs + SG函数应用)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1524 #include<stdio.h> #include<cstring> ...
- SPOJ CIRU - The area of the union of circles (圆的面积并)
CIRU - The area of the union of circles no tags You are given N circles and expected to calculate t ...
随机推荐
- Unity3D摄像机尾随人物
这里的镜头主要是从人物的背后尾随的. 首先新建一个C#脚本,命名为MyFollow,然后把下面代码粘贴进去.保存: using UnityEngine; using System.Collection ...
- 每天一个JavaScript实例-tab标签切换
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...
- 5.文件I/O
1 C标准函数与系统函数的区别 文件的结构体: 1.1 I/O缓冲区 每一个FILE文件流都有一个缓冲区buffer,默认大小8192Byte. 1.2 效率 文件缓冲区会降低效率.这里提供缓冲区主要 ...
- 13.QT多窗口切换list
Dialog::Dialog(QWidget *parent) : QDialog(parent), ui(new Ui::Dialog) { ui->setupUi(this); list = ...
- shell编程01—shell基础
01.学习shell编程需要的知识储备 1.vi.vim编辑器的命令,vimrc设置 2.命令基础,100多个命令 3.基础.高端的网络服务,nfs,rsync,inotify,lanmp,sersy ...
- BZOJ 3729 splay维护DFS序+博弈论
思路: 这像是 阶梯Nim之类的东西 我们 直接把sg函数 设成mod(L+1)的 一棵子树 向下的奇数层上的石子xor起来 就是答案 有加点和改值的操作 就splay维护一下 //By Sirius ...
- Java NIO(五)套接字通道
Socket通道 Socket通道和文件通道有着不一样的特征: Socket通道类可以运行于非阻塞模式,并且是可选的.这两个特征可以激活大程序(如网络服务和中间件组件)巨大的可伸缩性和灵活性,因此再也 ...
- 达夫设备之js
最近阅读<高性能JavaScript>时,在书中的“达夫设备“ . 对此,有些感悟,同时有些疑问,希望看到的朋友,能帮忙解释下,在此先提前感谢了. 1. 先说自己的理解吧: ”达夫设备“的 ...
- SQL--left join ,inner join, right jion, Limit
SQL Limit 语句 用于返回规定的数量记录.当数据库中的数据量十分庞大时,可以使用,返回指定的数量记录. 语句如:select * from grade limit 5.返回grade表中的前面 ...
- Oracle自制事务
数据库事务是一种单元操作,要么全部操作成功,要么全部失败.在Oracle中,一个事务是从执行第一个数据操作语言(DML)语句开始的,直到执行一个COMMIT语句,提交保存事务,或执行一个ROLLBAC ...