题面

自己去\(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 选圆圈(假题解)的更多相关文章

  1. 【LG4631】[APIO2018]Circle selection 选圆圈

    [LG4631][APIO2018]Circle selection 选圆圈 题面 洛谷 题解 用\(kdt\)乱搞剪枝. 维护每个圆在\(x.y\)轴的坐标范围 相当于维护一个矩形的坐标范围为\([ ...

  2. [Luogu4631][APIO2018] Circle selection 选圆圈

    Luogu 题目描述 在平面上,有 \(n\) 个圆,记为 \(c_1, c_2,...,c_n\) .我们尝试对这些圆运行这个算法: \(1\).找到这些圆中半径最大的.如果有多个半径最大的圆,选择 ...

  3. [APIO2018] Circle selection 选圆圈

    Description 给出 \(n\) 个圆 \((x_i,y_i,r_i)\) 每次重复以下步骤: 找出半径最大的圆,并删除与这个圆相交的圆 求出每一个圆是被哪个圆删除的 Solution \(k ...

  4. luogu P4631 [APIO2018] Circle selection 选圆圈

    传送门 那个当前半径最大的圆可以用堆维护.这道题一个想法就是优化找和当前圆有交的圆的过程.考虑对于所有圆心建KD-tree,然后在树上遍历的找这样的点.只要某个点子树内的点构成的矩形区域到当前圆心的最 ...

  5. 洛谷4631 [APIO2018] Circle selection 选圆圈 (KD树)

    qwq纪念AC450 一开始想这个题想复杂了. 首先,正解的做法是比较麻烦的. qwqq 那么就不如来一点暴力的东西,看到平面上点的距离的题,不难想到\(KD-Tree\) 我们用类似平面最近点对那个 ...

  6. [APIO2018]Circle selection

    https://www.zybuluo.com/ysner/note/1257597 题面 在平面上,有\(n\)个圆,记为\(c_1,c_2,...,c_n\).我们尝试对这些圆运行这个算法: 找到 ...

  7. 【APIO2018】选圆圈(平面分块 | CDQ分治 | KDT)

    Description 给定平面上的 \(n\) 个圆,用三个参数 \((x, y, R)\) 表示圆心坐标和半径. 每次选取最大的一个尚未被删除的圆删除,并同时删除所有与其相切或相交的圆. 最后输出 ...

  8. 「APIO2018选圆圈」

    「APIO2018选圆圈」 题目描述 在平面上,有 \(n\) 个圆,记为 \(c_1, c_2, \ldots, c_n\) .我们尝试对这些圆运行这个算法: 找到这些圆中半径最大的.如果有多个半径 ...

  9. 【LOJ2586】【APIO2018】选圆圈 CDQ分治 扫描线 平衡树

    题目描述 在平面上,有 \(n\) 个圆,记为 \(c_1,c_2,\ldots,c_n\) .我们尝试对这些圆运行这个算法: 找到这些圆中半径最大的.如果有多个半径最大的圆,选择编号最小的.记为 \ ...

随机推荐

  1. 关于找不到stdafx.h头文件问题(pass)

    代码: #include "stdafx.h" #include "stdlib.h" char* getcharBuffer() { return " ...

  2. Ionic2 启动加载优化总结

    1. ionic2通过ionic serve生成的main.js大于4M,必须先build才能部署 npm run ionic:build --prod 之后main.js缩小为大概100K+ 2. ...

  3. clang命令理解程序

    Xcode 创建一个mac OS   command Line Tool程序 步骤打开终端  cd + 工程路径(绝对路径)(注:拖拽main.m文件到终端) input —preprocessor— ...

  4. leetcode-852-山脉数组的峰顶索引

    题目描述: 我们把符合下列属性的数组 A 称作山脉: A.length >= 3 存在 0 < i < A.length - 1 使得A[0] < A[1] < ... ...

  5. C#-WebForm-AJAX阿贾克斯(二)★★★★★ajax的完整结构★★★★★

    ajax完整结构: $.ajax({ url:"",//服务器路径 data:{},//给服务端传递的参数,可以没有,也可以是多个 type:"post", / ...

  6. shell-005:备份。

    #  这个案例感觉有点绕,如果是本地机器备份完全没必要.下面带颜色的写法值得我们借鉴,所以还是做下笔记吧 #!/bin/bash # 找出//目录下所有txt结尾的文件,且形成一个列表清单的文件 fi ...

  7. Mac系统升级至OS X Mavericks后Genymotion出现的问题及解决方法

    Apple的系统升级终于免费了,可开心满满地升级到OS X Mavericks后,Android模拟器之王Genymotion罢工了.遇到两个问题:1. Unable to load VirtualB ...

  8. Mac 10.12安装VirtualBox

    说明:用VirtualBox主要是能开无缝模式. 下载: (链接: https://pan.baidu.com/s/1i5y78Ct 密码: e3bq)

  9. 【es6】数组扩展

    只有一个参数,为数组中的值.

  10. 【分步详解】两个有序数组中的中位数和Top K问题

    (这也是一道leetcode的经典题目:<LeetCode>解题笔记:004. Median of Two Sorted Arrays[H] 问题介绍 这是个超级超级经典的分治算法!!这个 ...