题解

不旋转坐标系,TLE,旋转坐标系,最慢一个点0.5s……maya,出题人数据水平很高了……

好吧,如果你不旋转坐标系,写一个正确性和复杂度未知的K - D树,没有优化,你可以得到87分的好成绩

但是你就是傻逼,你就是写不出来,能有什么办法,APIO Ag滚粗了呗= =

这道题看起来需要用什么东西维护一下平面,查找给定一个圆这个平面内多少个圆和它有交集,可以K - D树

我们考虑维护一个集合里的圆覆盖的矩形,就是最大的横纵坐标和最小的横纵坐标,查询的时候只要看看和当前圆横纵坐标是不是有交集,有交集就查,同时维护一下这棵树里还有没有圆没有被删除

当然复杂度可能会很劣……但是不劣的算法也不会,你就写了,写完之后87

哦87挺好的哦,然而不是考场上我想写写100分啊,看了大家似乎旋转了坐标系,然后我也转了,咦我怎么WA了……把eps调小一点就过了

为什么我那么菜啊= =

代码

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <map>
//#define ivorysi
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define mo 974711
#define MAXN 300005
#define eps 1e-3
#define RG register
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
res = 0;char c = getchar();T f = 1;
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 + c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {putchar('-');x = -x;}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
struct Point {
db x,y;
Point() {}
Point(db _x,db _y) {
x = _x;y = _y;
}
};
struct Circle {
Point a;db R;int id;
}cir[MAXN],C[MAXN];
db o(db x) {
return x * x;
}
db dist(Point a,Point b) {
return o(a.x - b.x) + o(a.y - b.y);
}
bool cmpc(Circle s,Circle t) {
return s.R > t.R || (s.R == t.R && s.id < t.id);
}
const db alpha = acos(-1.0) / 5;
int tr[MAXN * 4],pos[MAXN],N,D[MAXN],tot,a[MAXN];
bool vis[MAXN],dimension;
struct node {
Circle cir;Point r1,r2;
node *lc,*rc;int siz;
void update_siz() {
siz = 0;
if(!vis[cir.id]) siz = 1;
siz += lc->siz;
siz += rc->siz;
}
void update() {
r1.x = cir.a.x - cir.R;r1.y = cir.a.y - cir.R;
r2.x = cir.a.x + cir.R;r2.y = cir.a.y + cir.R;
r1.x = min(r1.x,min(lc->r1.x,rc->r1.x));
r1.y = min(r1.y,min(lc->r1.y,rc->r1.y));
r2.x = max(r2.x,max(lc->r2.x,rc->r2.x));
r2.y = max(r2.y,max(lc->r2.y,rc->r2.y));
}
}*rt,*null; bool cmp(Circle s,Circle t) {
if(dimension) return s.a.x + s.R + eps < t.a.x + t.R;
else return s.a.y + s.R + eps < t.a.y + t.R;
}
node* build(int l,int r,bool d) {
if(l > r) return null;
node *res = new node;
int mid = (l + r) >> 1;
dimension = d;
nth_element(C + l,C + mid,C + r + 1,cmp);
res->cir = C[mid];
res->lc = build(l,mid - 1,d ^ 1);res->rc = build(mid + 1,r,d ^ 1);
res->update();res->update_siz();
return res;
}
bool fit(node *u,Circle S) {
db l[2] = {u->r1.x,S.a.x - S.R};
db r[2] = {u->r2.x,S.a.x + S.R};
if(l[0] > l[1]) swap(l[0],l[1]),swap(r[0],r[1]);
if(l[1] > r[0]) return 0;
l[0] = u->r1.y,l[1] = S.a.y - S.R;
r[0] = u->r2.y,r[1] = S.a.y + S.R;
if(l[0] > l[1]) swap(l[0],l[1]),swap(r[0],r[1]);
if(l[1] > r[0]) return 0;
return 1;
}
void Query(node *u,Circle S) {
if(!u->siz) return;
if(!vis[u->cir.id]) {
if(dist(u->cir.a,S.a) <= o(u->cir.R + S.R) + eps) {
vis[u->cir.id] = 1;
a[u->cir.id] = S.id;
--tot;
}
}
if(fit(u->lc,S)) Query(u->lc,S);
if(fit(u->rc,S)) Query(u->rc,S);
u->update_siz();
}
void Init() {
null = new node;
null->siz = 0;
null->r1 = Point(2000000000,2000000000);
null->r2 = Point(-2000000000,-2000000000);
read(N);
db x,y,r;
for(int i = 1 ; i <= N ; ++i) {
scanf("%lf%lf%lf",&x,&y,&r);
cir[i] = (Circle){Point(x * cos(alpha) - y * sin(alpha),x * sin(alpha) + y * cos(alpha)),r,i};
C[i] = cir[i];
}
sort(cir + 1,cir + N + 1,cmpc);
rt = build(1,N,0);
}
void Solve() {
for(int i = 1 ; i <= N ; ++i) {
if(!a[cir[i].id]) Query(rt,cir[i]);
}
for(int i = 1 ; i <= N ; ++i) {
out(a[i]);if(i == N) enter;else space;
}
//out(clock());enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Init();
Solve();
return 0;
}

【LOJ】#2586. 「APIO2018」选圆圈的更多相关文章

  1. LOJ 2586 「APIO2018」选圆圈——KD树

    题目:https://loj.ac/problem/2586 只会 19 分的暴力. y 都相等,仍然按直径从大到小做.如果当前圆没有被删除,那么用线段树把 [ x-r , x+r ] 都打上它的标记 ...

  2. 「APIO2018」选圆圈

    传送门 Description 有\(n\)个圆,每次找到这些圆中半径最大中的编号最小的圆,删除ta及与其有交集的所有圆. 对于每个圆,求出它是被哪一个圆删除的. Solution  K-D Tree ...

  3. LOJ #2585. 「APIO2018」新家

    #2585. 「APIO2018」新家 https://loj.ac/problem/2585 分析: 线段树+二分. 首先看怎样数颜色,正常的时候,离线扫一遍右端点,每次只记录最右边的点,然后查询左 ...

  4. LOJ #2587「APIO2018」铁人两项

    是不是$ vector$存图非常慢啊...... 题意:求数对$(x,y,z)$的数量使得存在一条$x$到$z$的路径上经过$y$,要求$x,y,z$两两不同  LOJ #2587 $ Solutio ...

  5. LOJ 2587 「APIO2018」铁人两项——圆方树

    题目:https://loj.ac/problem/2587 先写了 47 分暴力. 对于 n<=50 的部分, n3 枚举三个点,把图的圆方树建出来,合法条件是 c 是 s -> f 路 ...

  6. LOJ 2585 「APIO2018」新家 ——线段树分治+二分答案

    题目:https://loj.ac/problem/2585 算答案的时候要二分! 这样的话,就是对于询问位置 x ,二分出一个最小的 mid 使得 [ x-mid , x+mid ] 里包含所有种类 ...

  7. 【刷题】LOJ 2587 「APIO2018」铁人两项

    题目描述 比特镇的路网由 \(m\) 条双向道路连接的 \(n\) 个交叉路口组成. 最近,比特镇获得了一场铁人两项锦标赛的主办权.这场比赛共有两段赛程:选手先完成一段长跑赛程,然后骑自行车完成第二段 ...

  8. loj#2016. 「SCOI2016」美味

    题目链接 loj#2016. 「SCOI2016」美味 题解 对于不带x的怎么做....可持久化trie树 对于带x,和trie树一样贪心 对于答案的二进制位,从高往低位贪心, 二进制可以表示所有的数 ...

  9. Loj #3102. 「JSOI2019」神经网络

    Loj #3102. 「JSOI2019」神经网络 题目背景 火星探险队发现,火星人的思维方式与人类非常不同,是因为他们拥有与人类很不一样的神经网络结构.为了更好地理解火星人的行为模式,JYY 对小镇 ...

随机推荐

  1. Codeforces 543.B Destroying Roads

    B. Destroying Roads time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  2. ios 字符串截取

    NSString *str = @"my name is jiemu"; 1.从第三个字符开始,截取长度为4的字符串 NSString *str2 = [str substring ...

  3. 【整理】explain、type、extra用法和结果的含义

    EXPLAIN列详情 详细解读:https://www.cnblogs.com/yycc/p/7338894.html explain显示了mysql如何使用索引来处理select语句以及连接表.可以 ...

  4. Parencodings(模拟)

    ZOJ Problem Set - 1016 Parencodings Time Limit: 2 Seconds      Memory Limit: 65536 KB Let S = s1 s2 ...

  5. CSS3之伪元素选择器和伪类选择器

    伪类选择器,和一般的DOM中的元素样式不一样,它并不改变任何DOM内容.只是插入了一些修饰类的元素,这些元素对于用户来说是可见的,但是对于DOM来说不可见.伪类的效果可以通过添加一个实际的类来达到. ...

  6. C#为何不推荐在构造函数中访问虚成员

    如果在一个类中定义了虚属性或者虚方法,又在构造函数中访问了这个虚属性或方法,此时VisualStudio是不会给出警告,并且编译也没有问题,但是如果安装了Resharper插件则会给出警告提示:&qu ...

  7. 【bzoj】2326 [HNOI2011]数学作业

    [题意]给定n和m,求1~n从高位到低位连接%m的结果.n=11时,ans=1234567891011%m.n<=10^18,m<=10^9. [算法]递推+矩阵快速幂 [题解] 考虑枚举 ...

  8. JavaScript使用数组

    for循环遍历 //js的数组里可以存各种类型 var arr =[1,5,true,false,'小明']; //遍历 for(var i=0;i<arr.length;i++){ alert ...

  9. C++ 内联函数inline

    http://blog.csdn.net/u011327981/article/details/50601800 1.  内联函数 在C++中我们通常定义以下函数来求两个整数的最大值: 复制代码 代码 ...

  10. dev_alloc_skb(len+16) skb_reserve(skb,2) skb_put(skb,len)

    /** *      dev_alloc_skb - allocate an skbuff for receiving *      @length: length to allocate * *   ...