2015 多校联赛 ——HDU5299(树删边)
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 593 Accepted Submission(s): 164
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。
1
0 0 1
6
-100 0 90
-50 0 1
-20 0 1
100 0 90
47 0 1
23 0 1
Bob
给出很多个园,要么相交,要么相离。如果删掉一个圆,则会删掉其中所有的。可以转化成树的删边
(咳咳!表示并不会这个方法,学习下 而且HDU上C++会超时)
树的删边游戏
规则如下:
给出一个有 N 个点的树,有一个点作为树的根节点。
游戏者轮流从树中删去边,删去一条边后,不与根节点相连的
部分将被移走。
谁无路可走谁输。
我们有如下定理:
[定理]
叶子节点的 SG 值为 0;
中间节点的 SG 值为它的所有子节点的 SG 值加 1 后的异或和
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
typedef unsigned long long ll;
const int N = 20003;
struct P
{
int x, y, r;
} p[N]; bool cmp(P a, P b)
{
return a.r < b.r;
}
int n; struct Edge
{
int v, next;
} e[N] ;
int head[N], m; void add(int from ,int to)
{
e[m].v = to;
e[m].next = head[from];
head[from] = m++;
} int dfs(int u)
{
int temp = 0;
for(int i = head[u];~i;i = e[i].next)
temp ^= dfs(e[i].v) + 1;
return temp;
} int main()
{
int re;
cin>>re;
while ( re-- )
{
memset(head, -1, sizeof head);
m= 0;
scanf("%d", &n);
for (int i=0; i<n; i++)
scanf("%d%d%d", &p[i].x, &p[i].y, &p[i].r);
sort(p ,p+n, cmp);
int rt = n;
for (int i=0; i<n; i++)
{
int flag = 0;
for (int j=i+1; j<n; j++) // r[j] > r[i]
{
ll a = ll((p[i].x-p[j].x)*(p[i].x-p[j].x))+ll((p[i].y-p[j].y)*(p[i].y-p[j].y));
ll b = ll(p[j].r - p[i].r)*ll(p[j].r - p[i].r);
if (a < b)
{
flag = 1;
add(j, i);
break;
}
}
if (!flag)
{
add(rt, i); //如果找不到一个圆可以包含,则用n包含,即虚拟最大的圆,可充当根节点
}
}
int ans = dfs(rt);
puts(ans ? "Alice" : "Bob");
}
return 0;
}
2015 多校联赛 ——HDU5299(树删边)的更多相关文章
- 2015 多校联赛 ——HDU5316(线段树)
Fantasy magicians usually gain their ability through one of three usual methods: possessing it as an ...
- 2015 多校联赛 ——HDU5372(树状数组)
Sample Input 3 0 0 0 3 0 1 5 0 1 0 0 1 1 0 1 0 0 Sample Output Case #1: 0 0 0 Case #2: 0 1 0 2 有0, ...
- 2015 多校联赛 ——HDU5294(最短路,最小切割)
Tricks Device Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) To ...
- 2015 多校联赛 ——HDU5325(DFS)
Crazy Bobo Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) Tota ...
- 2015 多校联赛 ——HDU5303(贪心)
Delicious Apples Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Other ...
- 2015 多校联赛 ——HDU5348(搜索)
Problem Description As we all kown, MZL hates the endless loop deeply, and he commands you to solve ...
- 2015 多校联赛 ——HDU5334(构造)
Virtual Participation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Ot ...
- 2015 多校联赛 ——HDU5302(构造)
Connect the Graph Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- 2015 多校联赛 ——HDU5323(搜索)
Solve this interesting problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ...
随机推荐
- 冲刺每日报告--Day1
敏捷冲刺每日报告--Day1 情况简介 由于李世钰同学出差了,周六才能回来.所以我们只能先写爬虫,封装代码提供接口等他回来调用. 任务进度 赵坤:编写了基本爬虫代码,目前能在国内有版权的B站.爱奇艺中 ...
- java实现同步的两种方式
同步是多线程中的重要概念.同步的使用可以保证在多线程运行的环境中,程序不会产生设计之外的错误结果.同步的实现方式有两种,同步方法和同步块,这两种方式都要用到synchronized关键字. 给一个方法 ...
- (原创)带模板的OLE输出EXCEL
其实带模板的OLE输出EXCEL就是将要输出的EXCEL中一些拥有固定值(如标题,表头行等)的单元格先填充好数据和设置好格式后作为模板上传到SAP 中.这样后续在输出EXCEL时只需从SAP中将模板下 ...
- Linux的安装和使用技巧
LinuxCentOs开始设置一个普通的用户,如果想进入root用户,可以su然后设置密码,然后第二次再次输入su,然后输入相同的密码就可以进去了 有很多命令需要在root下才能执行,但是在创建时却是 ...
- angular2 学习笔记 の 移动端开发 ( 手势 )
更新 : 2018-01-31 (hammer 的坑) hammer 的 pinch 在某种情况下会自动触发 panEnd,很奇葩. 解决方法就是记入时间呗 refer : https://githu ...
- Let's Encrypt,免费好用的 HTTPS 证书
很早之前我就在关注 Let's Encrypt 这个免费.自动化.开放的证书签发服务.它由 ISRG(Internet Security Research Group,互联网安全研究小组)提供服务,而 ...
- leetcode算法:Island Perimeter
You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represen ...
- eclipse使用git及github学习笔记
项目托管 1.首先需要在github上建立一个远端仓库 点击Create repository后,会在github上建立相应的git仓库,并会出现如下界面: 复制https或者ssh的仓库地址,远端 ...
- 通过wget工具下载指定文件中的URLs对应的资源并保存到指定的本地目录中去并进行文件完整性与可靠性校验
创建URLs文件在终端输入cd target_directory回车,便把当前文件夹切换到了目标文件夹target_directory,此后创建的文件都会丢它里面在终端输入cat > URLs回 ...
- 解析 Javascript - this
在函数中 this 到底取何值,是在函数真正被调用执行的时候确定下来的,函数定义的时候确定不了. 因为 this 的取值是执行上下文环境的一部分,每次调用函数,都会产生一个新的执行上下文环境.当你在 ...