HDU 5299 Circles Game
思路:
圆扫描线+树上删边博弈
圆扫描线有以下四种情况,用set维护扫描线与圆的交点,重载小于号

代码:
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define y1 y11
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pli pair<LL, int>
#define pii pair<int, int>
#define piii pair<pii, int>
#define pdd pair<double, double>
#define mem(a, b) memset(a, b, sizeof(a))
#define debug(x) cerr << #x << " = " << x << "\n"; const int N = 2e4 + ;
int nowx;
struct circle {
int x, y, r;
}p[N];
double Y(int id, int ty) {
if(ty == ) return p[id].y - sqrt(p[id].r*1.0*p[id].r - (nowx-p[id].x)*1.0*(nowx-p[id].x));
else return p[id].y + sqrt(p[id].r*1.0*p[id].r - (nowx-p[id].x)*1.0*(nowx-p[id].x));
}
struct node {
int id, ty;
bool operator < (const node &rhs) const {
if(id == rhs.id) return ty < rhs.ty;
else return Y(id, ty) < Y(rhs.id, rhs.ty);
}
};
set<node> s;
vector<int> g[N];
int T, n, dp[N], fa[N], sg[N];
piii t[N*];
void dfs(int u, int o) {
sg[u] = ;
for (int i = ; i < g[u].size(); ++i) {
int v = g[u][i];
if(v != o) {
dfs(v, u);
sg[u] ^= sg[v] + ;
}
}
}
int main() {
p[].x = p[].y = ;
p[].r = ;
s.insert({, });
s.insert({, });
scanf("%d", &T);
while(T--) {
scanf("%d", &n);
for (int i = ; i <= n; ++i) scanf("%d %d %d", &p[i].x, &p[i].y, &p[i].r);
for (int i = ; i <= n; ++i) {
t[i].fi.fi = p[i].x - p[i].r;
t[i].fi.se = ;
t[i].se = i;
t[n+i].fi.fi = p[i].x + p[i].r;
t[n+i].fi.se = ;
t[n+i].se = i;
}
sort(t+, t++*n);
for (int i = ; i <= *n; ++i) {
nowx = t[i].fi.fi;
int id = t[i].se;
node tmp = {id, };
if(t[i].fi.se == ) {
auto l = s.lower_bound(tmp); --l;
auto r = s.upper_bound(tmp);
if((*l).id == (*r).id) {
dp[id] = dp[(*l).id] + ;
fa[id] = (*l).id;
}
else if(dp[(*l).id] >= dp[(*r).id]) {
dp[id] = dp[(*l).id];
fa[id] = fa[(*l).id];
}
else {
dp[id] = dp[(*r).id];
fa[id] = fa[(*r).id]; }
g[fa[id]].pb(id);
s.insert({id, });
s.insert({id, });
}
else {
s.erase({id, });
s.erase({id, });
}
}
dfs(, );
if(sg[]) printf("Alice\n");
else printf("Bob\n");
for (int i = ; i <= n; ++i) g[i].clear(), sg[i] = fa[i] = dp[i] = ;
}
return ;
}
HDU 5299 Circles Game的更多相关文章
- HDU 5299 Circles Game 博弈论 暴力
Circles Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5299 Description There are n circles on ...
- 计数方法,博弈论(扫描线,树形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个圆,有包含关系,以这个关系做游戏,每次操作可以选择把一个圆及它内部的圆全部删除,不能操作者输. 圆的包含关系显然可以看做是树型结构,所以也就是树上删边的游戏. 而找圆的 ...
- HDOJ 5299 Circles Game 圆嵌套+树上SG
将全部的圆化成树,然后就能够转化成树上的删边博弈问题.... Circles Game Time Limit: 2000/1000 MS (Java/Others) Memory Limit: ...
- 2015 Multi-University Training Contest 1 题解&&总结
---------- HDU 5288 OO’s Sequence 题意 给定一个数列(长度<$10^5$),求有多少区间[l,r],且区间内有多少数,满足区间内其它数不是他的约数. 数的范围$ ...
- 算法笔记--sg函数详解及其模板
算法笔记 参考资料:https://wenku.baidu.com/view/25540742a8956bec0975e3a8.html sg函数大神详解:http://blog.csdn.net/l ...
- hdu 5779 Tower Defence
题意:考虑由$n$个结点构成的无向图,每条边的长度均为$1$,问有多少种构图方法使得结点$1$与任意其它节点之间的最短距离均不等于$k$(无法到达时距离等于无穷大),输出答案对$1e9+7$取模.$1 ...
- [2015hdu多校联赛补题]hdu5299 Circles Game
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5299 题意: 在欧几里得平面上有n个圆,圆之间不会相交也不会相切,现在Alice和Bob玩游戏,两人轮 ...
- POJ 1308&&HDU 1272 并查集判断图
HDU 1272 I - 小希的迷宫 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64 ...
随机推荐
- 完整工程,deeplab v3+(tensorflow)代码全理解及其运行过程,长期更新
前提:ubuntu+tensorflow-gpu+python3.6 各种环境提前配好 1.下载工程源码 网址:https://github.com/tensorflow/models 下载时会遇到速 ...
- Fiddler抓包【6】_Fiddler Script
1.安装SyntaxView插件 使用Fiddler Script前需要安装SyntaxView插件: 方式1:Inspectors tab--->Get SyntaxView tab---&g ...
- 安装linux虚拟机
虚拟机安装流程 1. 安装系统 安装完成 2. 安装VMware tools linux(ubuntu 18.04 Desktop) 手动安装 1) 加载光驱 2) 双击进入光驱,在光驱的目录下,打开 ...
- 详解Nginx服务器配置
#运行用户 user nobody; #启动进程,通常设置成和cpu的数量相等 worker_processes ; #全局错误日志及PID文件 #error_log logs/error.log; ...
- 2018-2019-2 网络对抗技术 20165335 Exp3 免杀原理与实践
一.免杀原理与基础知识: (1)杀软是如何检测出恶意代码的? 检测特征码:特征码就是一般程序都不会有的代码,而后门有的那种特别的数据,而一个程序,应用有这种代码,数据的话,就直接判定为恶意代码. 主流 ...
- Oracle生成GUID
,),),),),) GUID FROM ( SELECT SYS_GUID() GUID FROM DUAL )
- MongoDB 3.4 安装以 Windows 服务方式运行
1.首先从https://www.mongodb.com/download-center#community 下载社区版,企业版也是类似. 2.双击运行安装,可自定义安装路径,这里采用默认路径(C:\ ...
- CSS——img自适应div大小
代码如下: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <tit ...
- 设置webstorm自动删除行尾分号
- pyautogui
pip install PyGetWindow==0.0.1 pip install pyautogui https://www.cnblogs.com/dcb3688/p/4607980.html