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 ...
随机推荐
- selenium处理元素定位到了点击无效问题
在WEB自动化测试过程中,经常会遇到这样的问题: 元素定位到了,但是点击无效?有人可能会问了,怎么判断元素定位到了,这个问题很好判断 1.给元素加高亮显示 self.driver.execute_sc ...
- 一道有趣的JS问题
function Foo() { getName = function () { alert (1); }; return this; } Foo.getName = function () { al ...
- Unity 特写镜头
using UnityEngine; public class Camera_Feature : MonoBehaviour { public static Camera_Feature instan ...
- kafka安装教程
今天需要在新机器上安装一个kafka集群,其实kafka我已经装了十个不止了,但是没有一个是为生产考虑的,因此比较汗颜,今天好好地把kafka的安装以及配置梳理一下: 1,kafka版本选取: 现在我 ...
- 关于element组件中分页的一些个人思路
最近在用element,用到了它的分页这个组件,我这边的情况是,我前端请求数据,数据大概有20个的样子,把数据存在data的一个数组里面,用一个v-for循环遍历数组内容,并用div装起来,这样20个 ...
- GO : 斐波纳契数列
package main import "fmt" // fibonacci is a function that returns // a function that retur ...
- WebForm文件上传
用 FileUpload控件进行上传文件. <asp:FileUpload ID="FileUpload1" runat="server" /> ...
- Flask实战-留言板-使用Bootstrap-Flask简化页面编写
使用Bootstrap-Flask简化页面编写 扩展Bootstrap-Flask内置了可以快速渲染Bootstrap样式HTML组件的宏,并提供了内置的Bootstap资源,方便快速开发,使用它可以 ...
- vue获得当前页面URL动态拼接URL复制邀请链接方法
vue获得当前页面URL动态拼接URL复制邀请链接方法 当前页面完整url可以用 location.href路由路径可以用 this.$route.path路由路径参数 this.$route.par ...
- 小米系统获取root权限的完整教程
小米系统通过什么方法拥有root超级权限?我们都清楚,安卓机器有root超级权限,如果手机拥有root相关权限,能够实现更好的功能,打个比方我们企业的营销部门的同事,使用大多数营销应用都需要在root ...