[APIO2018] Circle selection 选圆圈(假题解)
题面
自己去\(LOJ\)上找
Sol
直接排序然后\(KDTree\)查询
然后发现\(TLE\)了
然后把点旋转一下,就过了。。
# include <bits/stdc++.h>
# define IL inline
# define RG register
# define Fill(a, b) memset(a, b, sizeof(a))
using namespace std;
typedef long long ll;
IL int Input(){
RG int x = 0, z = 1; RG char c = getchar();
for(; c < '0' || c > '9'; c = getchar()) z = c == '-' ? -1 : 1;
for(; c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
return x * z;
}
const int maxn(3e5 + 5);
const double eps(1e-3);
const double alpha(acos(-1) / 5);
const double cosa(cos(alpha));
const double sina(sin(alpha));
int n, ans[maxn], op, rt;
struct Data{
double d[2], r;
int id;
IL int operator <(RG Data b) const{
return d[op] < b.d[op];
}
} a[maxn];
IL int Cmp(RG Data x, RG Data y){
return x.r != y.r ? x.r > y.r : x.id < y.id;
}
struct KDTree{
double d[2], mn[2], mx[2], r;
int ls, rs, id;
} tr[maxn];
IL void Chkmax(RG double &x, RG double y){
if(y > x) x = y;
}
IL void Chkmin(RG double &x, RG double y){
if(y < x) x = y;
}
IL void Update(RG int x){
tr[x].mn[0] = tr[x].mx[0] = tr[x].d[0];
tr[x].mn[1] = tr[x].mx[1] = tr[x].d[1];
RG int ls = tr[x].ls, rs = tr[x].rs;
if(ls){
Chkmin(tr[x].mn[0], tr[ls].mn[0]), Chkmin(tr[x].mn[1], tr[ls].mn[1]);
Chkmax(tr[x].mx[0], tr[ls].mx[0]), Chkmax(tr[x].mx[1], tr[ls].mx[1]);
}
if(rs){
Chkmin(tr[x].mn[0], tr[rs].mn[0]), Chkmin(tr[x].mn[1], tr[rs].mn[1]);
Chkmax(tr[x].mx[0], tr[rs].mx[0]), Chkmax(tr[x].mx[1], tr[rs].mx[1]);
}
}
IL int Build(RG int l, RG int r, RG int nop){
RG int x = (l + r) >> 1; op = nop;
nth_element(a + l, a + x, a + r + 1);
tr[x].d[0] = a[x].d[0], tr[x].d[1] = a[x].d[1];
tr[x].id = a[x].id, tr[x].r = a[x].r;
if(l < x) tr[x].ls = Build(l, x - 1, nop ^ 1);
if(r > x) tr[x].rs = Build(x + 1, r, nop ^ 1);
Update(x);
return x;
}
# define Sqr(x) ((x) * (x))
IL int Check(RG int x, RG Data p){
RG double x1 = tr[x].d[0], y1 = tr[x].d[1], x2 = p.d[0], y2 = p.d[1], r1 = tr[x].r, r2 = p.r;
return Sqr(x1 - x2) + Sqr(y1 - y2) - eps <= Sqr(r1 + r2);
}
IL int Cut(RG int x, RG Data p){
RG double x2 = p.d[0], y2 = p.d[1], r = p.r + p.r;
if(x2 + r + eps < tr[x].mn[0]) return 1;
if(y2 + r + eps < tr[x].mn[1]) return 1;
if(x2 - r > tr[x].mx[0] + eps) return 1;
if(y2 - r > tr[x].mx[1] + eps) return 1;
return 0;
}
IL void Modify(RG int x, RG Data p){
if(Cut(x, p)) return;
if(!ans[tr[x].id] && Check(x, p)) ans[tr[x].id] = p.id;
if(tr[x].ls) Modify(tr[x].ls, p);
if(tr[x].rs) Modify(tr[x].rs, p);
}
int main(){
n = Input();
for(RG int i = 1; i <= n; ++i){
RG double x = Input(), y = Input(), r = Input();
a[i] = (Data){x * cosa - y * sina, x * sina + y * cosa, r, i};
}
rt = Build(1, n, 0), sort(a + 1, a + n + 1, Cmp);
for(RG int i = 1; i <= n; ++i)
if(!ans[a[i].id]) Modify(rt, a[i]);
for(RG int i = 1; i <= n; ++i) printf("%d ", ans[i]);
return 0;
}
[APIO2018] Circle selection 选圆圈(假题解)的更多相关文章
- 【LG4631】[APIO2018]Circle selection 选圆圈
[LG4631][APIO2018]Circle selection 选圆圈 题面 洛谷 题解 用\(kdt\)乱搞剪枝. 维护每个圆在\(x.y\)轴的坐标范围 相当于维护一个矩形的坐标范围为\([ ...
- [Luogu4631][APIO2018] Circle selection 选圆圈
Luogu 题目描述 在平面上,有 \(n\) 个圆,记为 \(c_1, c_2,...,c_n\) .我们尝试对这些圆运行这个算法: \(1\).找到这些圆中半径最大的.如果有多个半径最大的圆,选择 ...
- [APIO2018] Circle selection 选圆圈
Description 给出 \(n\) 个圆 \((x_i,y_i,r_i)\) 每次重复以下步骤: 找出半径最大的圆,并删除与这个圆相交的圆 求出每一个圆是被哪个圆删除的 Solution \(k ...
- luogu P4631 [APIO2018] Circle selection 选圆圈
传送门 那个当前半径最大的圆可以用堆维护.这道题一个想法就是优化找和当前圆有交的圆的过程.考虑对于所有圆心建KD-tree,然后在树上遍历的找这样的点.只要某个点子树内的点构成的矩形区域到当前圆心的最 ...
- 洛谷4631 [APIO2018] Circle selection 选圆圈 (KD树)
qwq纪念AC450 一开始想这个题想复杂了. 首先,正解的做法是比较麻烦的. qwqq 那么就不如来一点暴力的东西,看到平面上点的距离的题,不难想到\(KD-Tree\) 我们用类似平面最近点对那个 ...
- [APIO2018]Circle selection
https://www.zybuluo.com/ysner/note/1257597 题面 在平面上,有\(n\)个圆,记为\(c_1,c_2,...,c_n\).我们尝试对这些圆运行这个算法: 找到 ...
- 【APIO2018】选圆圈(平面分块 | CDQ分治 | KDT)
Description 给定平面上的 \(n\) 个圆,用三个参数 \((x, y, R)\) 表示圆心坐标和半径. 每次选取最大的一个尚未被删除的圆删除,并同时删除所有与其相切或相交的圆. 最后输出 ...
- 「APIO2018选圆圈」
「APIO2018选圆圈」 题目描述 在平面上,有 \(n\) 个圆,记为 \(c_1, c_2, \ldots, c_n\) .我们尝试对这些圆运行这个算法: 找到这些圆中半径最大的.如果有多个半径 ...
- 【LOJ2586】【APIO2018】选圆圈 CDQ分治 扫描线 平衡树
题目描述 在平面上,有 \(n\) 个圆,记为 \(c_1,c_2,\ldots,c_n\) .我们尝试对这些圆运行这个算法: 找到这些圆中半径最大的.如果有多个半径最大的圆,选择编号最小的.记为 \ ...
随机推荐
- mybatis一级缓存与二级缓存的原理
1.mybatis中的缓存是在mybatis框架中的Executor中来实现的,我们来看一下Executor的继承图 2.通过以上类图我们可以发现Executor接口下有两大实现类BaseExecut ...
- Python之scrapy框架之post传输数据错误:TypeError: to_bytes must receive a unicode, str or bytes object, got int
错误名:TypeError: to_bytes must receive a unicode, str or bytes object, got int 错误翻译:类型错误:to_bytes必须接收u ...
- 往word中插入美观的代码
http://www.planetb.ca/syntax-highlight-word 选择需要的语言,然后Show Highlighted,复制跳转页面显示的代码至word即可
- 【Python】解析Python的标准数据类型
目录结构: contents structure [-] 数值(Number) 数值类型 类型转化 Python中的Decimal数据类型 Python中的分数 Python中的算术方法 字符串(St ...
- vue-cli3 chainWebpack配置,去除打包后文件的预加载prefetch/preload(已解决)
//细节配置修改 chainWebpack: config => { console.log(config,'chainWebpack') // 移除 prefetch 插件 config.pl ...
- 在Azuer创建自己的Linux_VM
---恢复内容开始--- emm..就是想搭个自己的VPN去YouTube看看视屏找找资源什么的... (滑稽.jpg)然后发现似乎需要这个玩意儿 先去申请一个Azuer账户 然后根据要求一步步来就好 ...
- error occurred during initialization of vm
虚拟机无法进行如下分配 : -Xmx2048m -XX:MaxPermSize=512m 原因是我的老爷机总共内存只有3G: settings - > 搜索VM ->找到Compiler ...
- [转] 手动上传jar包到远程仓库 (maven deploy)
[From] https://my.oschina.net/360yg/blog/1588899 前言:通常允许上传的远程仓库有两种:Snapshots和Releases,分别为快照版仓库和稳定版仓库 ...
- 剑指offer——面试题29:顺时针打印矩阵
#include"iostream" #include"stdio.h" using namespace std; void PrintMatrixInCirc ...
- Mac 10.12安装hosts快速切换工SwitchHosts!
说明:支持在线本地. 下载: (链接: https://pan.baidu.com/s/1boDw67d 密码: uy6g)