HDU 5299

思路:

圆扫描线+树上删边博弈

圆扫描线有以下四种情况,用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的更多相关文章

  1. HDU 5299 Circles Game 博弈论 暴力

    Circles Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5299 Description There are n circles on ...

  2. 计数方法,博弈论(扫描线,树形SG):HDU 5299 Circles Game

    There are n circles on a infinitely large table.With every two circle, either one contains another o ...

  3. HDU 5299 圆扫描线 + 树上删边

    几何+博弈的简单组合技 给出n个圆,有包含关系,以这个关系做游戏,每次操作可以选择把一个圆及它内部的圆全部删除,不能操作者输. 圆的包含关系显然可以看做是树型结构,所以也就是树上删边的游戏. 而找圆的 ...

  4. HDOJ 5299 Circles Game 圆嵌套+树上SG

    将全部的圆化成树,然后就能够转化成树上的删边博弈问题.... Circles Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: ...

  5. 2015 Multi-University Training Contest 1 题解&&总结

    ---------- HDU 5288 OO’s Sequence 题意 给定一个数列(长度<$10^5$),求有多少区间[l,r],且区间内有多少数,满足区间内其它数不是他的约数. 数的范围$ ...

  6. 算法笔记--sg函数详解及其模板

    算法笔记 参考资料:https://wenku.baidu.com/view/25540742a8956bec0975e3a8.html sg函数大神详解:http://blog.csdn.net/l ...

  7. hdu 5779 Tower Defence

    题意:考虑由$n$个结点构成的无向图,每条边的长度均为$1$,问有多少种构图方法使得结点$1$与任意其它节点之间的最短距离均不等于$k$(无法到达时距离等于无穷大),输出答案对$1e9+7$取模.$1 ...

  8. [2015hdu多校联赛补题]hdu5299 Circles Game

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5299 题意: 在欧几里得平面上有n个圆,圆之间不会相交也不会相切,现在Alice和Bob玩游戏,两人轮 ...

  9. POJ 1308&&HDU 1272 并查集判断图

      HDU 1272 I - 小希的迷宫 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64 ...

随机推荐

  1. 项目从.net core 2.1.0升级到.net core 2.2.4,原有项目出错及解决方案

    ... 1.Controller中的形参命名为query.pager,且里面实体中的参数也有Query.Pager参数时,Query.Pager 就会无数据. 解决方案: 形参query.pager ...

  2. 二维码图片以字符串的形式保存DB,已文件流显示页面上

    以下是生成二维码的方法,我只用其中一个方法 这个需要引用ZXing.DLL 链接:https://pan.baidu.com/s/1mCTwHiAm_awtsPcibAotZw 提取码:ufp6 pu ...

  3. javascript中获取字符串或数组中元素的索引

    有些时候,我们需要知道一个字符串中字符的位置,或者一个数组中元素的位置,这是就需要对该变量进行迭代操作. 对于数组,有两个方法indexOf和findIndex() , 需要注意的是,findInde ...

  4. 5个最好的TensorFlow网络课程

    1. Introduction to TensorFlow for Artificial Intelligence, Machine Learning and Deep Learning This c ...

  5. 【论文速读】Chuhui Xue_ECCV2018_Accurate Scene Text Detection through Border Semantics Awareness and Bootstrapping

    Chuhui Xue_ECCV2018_Accurate Scene Text Detection through Border Semantics Awareness and Bootstrappi ...

  6. rabbitMQ Management http://localhost:15672/ 打不开

    C:\RabbitMQ Server\rabbitmq_server-3.7.7\sbin>rabbitmq-plugins enable rabbitmq_management 安装rabbi ...

  7. Java中使用dom4j处理xml类型的文本

    在Java的实际开发中经常会碰到xml文件的解析,需要获取固定节点的内容,在这里简单记录一下,方便下次使用时查阅: 1.VSCode中安装插件XML Format,Shift + Alt + F撸直x ...

  8. mysql_study_4

    索引 ALTER TABLE 表名字 ADD INDEX 索引名 (列名); CREATE INDEX 索引名 ON 表名字 (列名); 索引的效果就是加快查询速度,当表中数据不够多的时候是感受不出他 ...

  9. python习题一

    1.26个字母大小写成对打印,例如:Aa,Bb...... 方法1: for i in range(26): print(chr(65+i)+chr(97+i)) 方法2: for i in rang ...

  10. my work

    Dad, what's your first job? How did you achieved?