HDU 5299 Circles Game 博弈论 暴力
Circles Game
题目连接:
http://acm.hdu.edu.cn/showproblem.php?pid=5299
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
Hint
题意
有一个平面,平面上有n个圆,圆与圆之间只有相离和包含的关系。
然后他们开始跑博弈论。
每个人可以拿圆和他所包含的圆。
如果谁不能拿了的话,那就输了。
问你谁能赢。
题解:
很显然,包含和相离关系,那么就是一个森林之间的关系。
然后把这个森林需要建立出来,这个就直接暴力就好了。
然后后面的博弈是一个很经典的东西。
叶子节点的SG值为0;中间节点的SG值为它的所有子节点的SG值加1 后的异或和。
然后直接跑就好了。
代码
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+6;
vector<int> E[maxn];
struct node
{
int x,y,r;
};
node a[maxn];
int dp[maxn];
bool cmp(node A,node B)
{
return A.r>B.r;
}
int fa[maxn];
bool check(node A,node B)
{
long long k = 1ll*(A.x-B.x)*(A.x-B.x)+1ll*(A.y-B.y)*(A.y-B.y);
return k<=1ll*A.r*A.r;
}
void init()
{
memset(a,0,sizeof(a));
memset(fa,0,sizeof(fa));
memset(dp,0,sizeof(dp));
for(int i=0;i<maxn;i++)E[i].clear();
}
void dfs(int x,int fa)
{
dp[x]=0;
for(int j=0;j<E[x].size();j++)
{
int v = E[x][j];
if(v==fa)continue;
dfs(v,x);
dp[x]^=(dp[v]+1);
}
}
void solve()
{
init();
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].r);
node k;
a[0].x=0,a[0].y=0,a[0].r=4e4+6;
sort(a+1,a+1+n,cmp);
for(int i=1;i<=n;i++)
{
for(int j=i-1;j>=0;j--)
if(check(a[j],a[i]))
{
fa[i]=j;
E[j].push_back(i);
break;
}
}
dfs(0,-1);
if(dp[0])cout<<"Alice"<<endl;
else cout<<"Bob"<<endl;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)solve();
}
HDU 5299 Circles Game 博弈论 暴力的更多相关文章
- HDU 5299 Circles Game
HDU 5299 思路: 圆扫描线+树上删边博弈 圆扫描线有以下四种情况,用set维护扫描线与圆的交点,重载小于号 代码: #pragma GCC optimize(2) #pragma GCC op ...
- 计数方法,博弈论(扫描线,树形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 圆扫描线 + 树上删边
几何+博弈的简单组合技 给出n个圆,有包含关系,以这个关系做游戏,每次操作可以选择把一个圆及它内部的圆全部删除,不能操作者输. 圆的包含关系显然可以看做是树型结构,所以也就是树上删边的游戏. 而找圆的 ...
- HDU.2149 Public Sale (博弈论 巴什博弈)
HDU.2149 Public Sale (博弈论 巴什博弈) 题意分析 巴什博奕裸题 博弈论快速入门 代码总览 #include <bits/stdc++.h> using namesp ...
- HDU.1846 Brave Game (博弈论 巴什博弈)
HDU.1846 Brave Game (博弈论 巴什博弈) 题意分析 巴什博奕裸题 博弈论快速入门 代码总览 include <bits/stdc++.h> using namespac ...
- HDU 2920 分块底数优化 暴力
其实和昨天写的那道水题是一样的,注意爆LL $1<=n,k<=1e9$,$\sum\limits_{i=1}^{n}(k \mod i) = nk - \sum\limits_{i=1}^ ...
- hdu 5277 YJC counts stars 暴力
YJC counts stars Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...
- HDU 5762 Teacher Bo (暴力)
Teacher Bo 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5762 Description Teacher BoBo is a geogra ...
- hdu 4712 Hamming Distance(随机函数暴力)
http://acm.hdu.edu.cn/showproblem.php?pid=4712 Hamming Distance Time Limit: 6000/3000 MS (Java/Other ...
随机推荐
- gcc中的内嵌汇编语言(Intel i386平台)
[转]http://bbs.chinaunix.net/thread-2149855-1-1.html 一.声明 虽然Linux的核心代码大部分是用C语言编写的,但是不可避免的其中还是有一部分是用汇 ...
- 一个文档让vim飞起来
原文地址:http://www.cnblogs.com/songfy/p/5635757.html 引言 今天我们特地来讲讲这个vim的配置. vim这东西, 很多人装逼的时候经常会提到, 不过大部分 ...
- 解决linux下终端无法输入的假死问题
有时在linux下shell终端中,会突然出现终端应用卡死,无法接受键盘输入, 但是其它分屏, 系统都是正常的.这本来是一个终端的很老的功能, 叫软件流控制(XON/XOFF flow control ...
- python基础===Excel处理库openpyxl
openpyxl是一个第三方库,可以处理xlsx格式的Excel文件. 安装: pip install openpyxl 对如下excel进行读取操作,如图: from openpyxl import ...
- 一个朋友 js图表开发问题 用 c和 js 解决
引言 不求知道一切, 只求发现一件 -- 乔治·西蒙·欧姆 附注:那些存在于梦幻中的事迹,那些儿时梦中的人物,每每看起,都觉得 .哎 .... 岁月 ... 一直在努力 ... ...
- 使用IDEA从github中下载fastdfs-client-java
由于在pom文件中加入依赖坐标无法将fastdfs-client-java下载下来,后来通过查资料,发现在中央仓库中没有定义该坐标.为此,使用idea从github下载fastdfs-client-j ...
- 获取分组后的TOP 1和TOP N记录
MySQL获取分组后的TOP 1和TOP N记录 有时会碰到一些需求,查询分组后的最大值,最小值所在的整行记录或者分组后的top n行的记录,在一些别的数据库可能有窗口函数可以方面的查出来,但是MyS ...
- linux命令(4):vmstat命令
CPU监控如下: vmstat 2 10 //表示每隔2秒运行10次 内存监控如下: vmstat –s 监控进程及CPU.内存状态 如下: top
- hdu 3435(KM算法最优匹配)
A new Graph Game Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- c# 发送web请求
我们目前涉及到的现有的接收请求方式有三种, 第一种: 页面式的Form表单 第二种: 服务的webservice形式的xml 第三个: restful风格的post包体json 第一种比较老,博客园的 ...