计数方法,博弈论(扫描线,树形SG):HDU 5299 Circles Game
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
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
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
这道题目可以说是模板题……
就是那个SG函数的求法貌似是结论,我不会证明。
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <set>
using namespace std;
const int N=,M=;
int cnt,fir[N],to[N],nxt[N];
void addedge(int a,int b){
nxt[++cnt]=fir[a];
to[fir[a]=cnt]=b;
}
int sqr(int x){return x*x;}
int tmp;
struct Circle{
int x,y,r;
Circle(int _=,int __=,int ___=){x=_;y=__;r=___;}
}c[N]; struct Point{
int x,id,tp;
Point(int _=,int __=,int ___=){x=_;id=__;tp=___;}
friend bool operator<(Point a,Point b){
double x=c[a.id].y+a.tp*sqrt(sqr(c[a.id].r)-sqr(tmp-c[a.id].x));
double y=c[b.id].y+b.tp*sqrt(sqr(c[b.id].r)-sqr(tmp-c[b.id].x));
if(x!=y)return x<y;return a.tp<b.tp;
}
}st[M]; bool cmp(Point a,Point b){return a.x<b.x;}
set<Point>s;set<Point>::iterator it; int fa[N],sg[N];
int DFS(int x){
sg[x]=;
for(int i=fir[x];i;i=nxt[i])
sg[x]^=DFS(to[i])+;
return sg[x];
} void Init(){
memset(fir,,sizeof(fir));
cnt=;
}
int T,n;
int main(){
scanf("%d",&T);
while(T--){
Init();scanf("%d",&n);
for(int i=;i<=n;i++){
scanf("%d%d%d",&c[i].x,&c[i].y,&c[i].r);
st[*i-]=Point(c[i].x-c[i].r,i,-);
st[*i]=Point(c[i].x+c[i].r,i,);
}
sort(st+,st+*n+,cmp);
for(int i=;i<=*n;i++){
Point x=st[i];tmp=x.x;
if(x.tp==-){
it=s.upper_bound(Point(,x.id,));
if(it==s.end())addedge(fa[x.id]=,x.id);
else{
Point y=*it;
if(y.tp==)
addedge(fa[x.id]=y.id,x.id);
else
addedge(fa[x.id]=fa[y.id],x.id);
}
s.insert(Point(,x.id,));
s.insert(Point(,x.id,-));
}
else{
s.erase(Point(,x.id,));
s.erase(Point(,x.id,-));
}
}
printf(DFS()?"Alice\n":"Bob\n");
}
return ;
}
计数方法,博弈论(扫描线,树形SG):HDU 5299 Circles Game的更多相关文章
- HDU 5299 Circles Game
		
HDU 5299 思路: 圆扫描线+树上删边博弈 圆扫描线有以下四种情况,用set维护扫描线与圆的交点,重载小于号 代码: #pragma GCC optimize(2) #pragma GCC op ...
 - HDU 5299 Circles Game 博弈论 暴力
		
Circles Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5299 Description There are n circles on ...
 - 计数方法(扫描线):JLOI 2016 圆的异或并
		
Description 在平面直角坐标系中给定N个圆.已知这些圆两两没有交点,即两圆的关系只存在相离和包含.求这些圆的异或面 积并.异或面积并为:当一片区域在奇数个圆内则计算其面积,当一片区域在偶数个 ...
 - HDU 5299 圆扫描线 + 树上删边
		
几何+博弈的简单组合技 给出n个圆,有包含关系,以这个关系做游戏,每次操作可以选择把一个圆及它内部的圆全部删除,不能操作者输. 圆的包含关系显然可以看做是树型结构,所以也就是树上删边的游戏. 而找圆的 ...
 - 【spring data jpa】jpa中使用count计数方法
		
spring data jpa中使用count计数方法很简单 直接在dao层写方法即可 int countByUidAndTenementId(String parentUid, String ten ...
 - 【概率论】1-2:计数方法(Counting Methods)
		
title: [概率论]1-2:计数方法(Counting Methods) categories: Mathematic Probability keywords: Counting Methods ...
 - fwt优化+树形DP HDU 5909
		
//fwt优化+树形DP HDU 5909 //见官方题解 // BestCoder Round #88 http://bestcoder.hdu.edu.cn/ #include <bits/ ...
 - 博弈论进阶之SG函数
		
SG函数 个人理解:SG函数是人们在研究博弈论的道路上迈出的重要一步,它把许多杂乱无章的博弈游戏通过某种规则结合在了一起,使得一类普遍的博弈问题得到了解决. 从SG函数开始,我们不再是单纯的同过找规律 ...
 - 博弈论基础之sg函数与nim
		
在算法竞赛中,博弈论题目往往是以icg.通俗的说就是两人交替操作,每步都各自合法,合法性与选手无关,只与游戏有关.往往我们需要求解在某一个游戏或几个游戏中的某个状态下,先手或后手谁会胜利的问题.就比如 ...
 
随机推荐
- 02_Jquery_02_元素选择器
			
[简述] 元素选择器就是通过元素名来查询元素 $("elementName")这里就可以通过元素名来获取jquery元素了. 但与id选择器不同的是,名称相同的元素有很多,所以获取 ...
 - OpenCV(2)-Mat数据结构及访问Mat中像素
			
Mat数据结构 一开始OpenCV是基于C语言的,在比较早的教材例如<学习OpenCV>中,讲解的存储图像的数据结构还是IplImage,这样需要手动管理内存.现在存储图像的基本数据结构是 ...
 - devenv 命令用法
			
devenv是VisualStudio的可执行程序,一般安装在“C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE”下. 这 ...
 - IOS分类(Category)
			
分类(Category):拓展原有类的方法,而不影响原有类的子类,分类中不能创建成员变量. 分类的使用: 1.创建分类: 如图点击(File)选择(New)->(File).. 或者使用快捷键c ...
 - 深入理解Python中的生成器
			
生成器(generator)概念 生成器不会把结果保存在一个系列中,而是保存生成器的状态,在每次进行迭代时返回一个值,直到遇到StopIteration异常结束. 生成器语法 生成器表达式: 通列表解 ...
 - samba和squid 安装
			
一. samba配置1. 什么是sambaSamba服务类似于windows上的共享功能,可以实现在Linux上共享文件,windows上访问,当然在Linux上也可以访问到.是一种在局域网上共享文件 ...
 - Linux网络应用编程之Packet Tracer安装及界面介绍
			
Packet Tracer入门 一,Packet Tracer介绍 packet tracer 是由Cisco公司发布的一个辅助学习工具,为学习思科网络课程的初学者去设计.配置.排除网络故障提供了网络 ...
 - sqlserver字符串转日期
			
declare @str varchar(15) declare @dt datetime select @str='2005-8-26' set @d ...
 - apache .htaccess 伪静态重定向,防盗链 限制下载...
			
301全站跳转 RewriteEngine OnRewriteCond %{HTTP_HOST} ^www\.old\.net$ [NC]RewriteRule ^(.*)$ http://www.n ...
 - emment语法
			
emment插件语法.md 元素 div → <div></div>foo → <foo></foo> 嵌套运算符 子: > div>ul& ...