计数方法,博弈论(扫描线,树形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.通俗的说就是两人交替操作,每步都各自合法,合法性与选手无关,只与游戏有关.往往我们需要求解在某一个游戏或几个游戏中的某个状态下,先手或后手谁会胜利的问题.就比如 ...
随机推荐
- javascript DOM 节点 第18节
<html> <head> <title>DOM对象</title> </head><body><div >DOM对 ...
- JavaScript使用技巧
使用!!操作符转换布尔值 有时候我们需要对一个变量查检其是否存在或者检查值是否有一个有效值,如果存在就返回true值.为了做这样的验证,我们可以使用!!操作符来实现是非常的方便与简单.对于变量可以使用 ...
- P1396 营救
P1396 营救 218 通过 571 提交 题目提供者yeszy 标签 二分 图论 并查集 福建省历届夏令营 难度 普及- 题目描述 "咚咚咚--""查水表!" ...
- python 自动化之路 day 03
内容目录: 1. 字典 2. 集合 3. 文件处理 4. 字符编码 1. 字典操作 字典一种key - value 的数据类型,使用就像我们上学用的字典,通过笔划.字母来查对应页的详细内容. 语法 ...
- 快速理解webStroage
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...
- PHP - 传入WebService服务端带中文字符的序列化字串不能反序列化的解决方法
因工作需要,用了web服务,通过远程调用的方式来检索雅虎拍卖数据.前几天遇到一个问题,现在记录一下 客户端: $res = $this->client->call('Get_YahooDa ...
- yum安装lamp环境
装了好些次lamp环境了,都没好好总结下,现在总结下 ^ ^ 1.替换163的yum源 1.检查系统版本 cat /etc/redhat-releas (我的版本是CentOS release 6 ...
- validate插件的使用
方法如下: 插件: jquery.validate.js jquery.validate.custom.js bootstrap html代码: <form id="form_name ...
- copy,retain,assign,strong,weak的区别
引用地址:http://www.aichengxu.com/view/32930 一.assign,copy,retain 1.copy是内容复制,新建一个相同内容的不同指针,retain为指针复制, ...
- linq any()方法实现sql in()方法的效果
public IQueryable<Vsec009ComSecComp> QueryList(Sec009ComSecCompQueryCondition condition) { var ...