题解

不旋转坐标系,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. 这年头不会点Git真不行!!!

    版本控制 说到版本控制,脑海里总会浮现大学毕业是写毕业论文的场景,你电脑上的毕业论文一定出现过这番景象! 1 2 3 4 5 6 7 8 9 10 11 毕业论文_初稿.doc 毕业论文_修改1.do ...

  2. IBatisNet+Oracle.ManagedDataAccess打造无需安装oracle客户端和ODP即可连接oracle数据库

    库环境: Oracle.ManagedDataAccess 版本:4.122.1.0 IBatisNet  版本:1.6.2 其实很简单的,只需在驱动配置那里添加上Oracle.ManagedData ...

  3. 将本地项目和远程git仓库相连接

    有时候写代码,是存在本地的,远程仓库没有对应的代码库,这个时候就需要把本地的代码项目与远程git库连接并推送. 1. 将项目文件添加到仓库中 本地的项目文档: 添加项目文件 git add . 2. ...

  4. HDU 6158 笛卡尔定理 几何

    LINK 题意:一个大圆中内切两个圆,三个圆两两相切,再不断往上加新的相切圆,问加上的圆的面积和.具体切法看图 思路:笛卡尔定理: 若平面上四个半径为r1.r2.r3.r4的圆两两相切于不同点,则其半 ...

  5. Python学习笔记(三十一)正则表达式

    ---恢复内容开始--- 摘抄自:https://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000 ...

  6. Ubuntu 14.04 安装Visual studio Code

    上一篇简单介绍了Ubuntu 14.04上如何创建.运行 hello world 程序. 这篇介绍Ubuntu 14.04如何安装Visual studio Code. 网上推荐的有通过Ubuntu ...

  7. Codeforces Round #420 (Div. 2) A-E

    本来打算划划水洗洗睡了,突然听到这次的主人公是冈部伦太郎 石头门(<steins;gate>)主题的比赛,岂有不打之理! 石头门真的很棒啊!人设也好剧情也赞曲子也特别好听. 推荐http: ...

  8. 【CodeForces】704 C. Black Widow 动态规划+模拟

    [题目]C. Black Widow [题意]给定一个表达式,形式为(...)^(...)^......^(...)=1(n个括号),括号中为1~2个值取或.有m个变量,给出表达式的值为xi或 !xi ...

  9. 2017ACM暑期多校联合训练 - Team 8 1002 HDU 6134 Battlestation Operational (数论 莫比乌斯反演)

    题目链接 Problem Description The Death Star, known officially as the DS-1 Orbital Battle Station, also k ...

  10. spring mvc convention over configuration 之 RequestToViewNameTranslator

    1. RequestToViewNameTranslator简介 在springmvc中很多地方都是约定优于配置的,比如这种写法: @Controller public class IndexActi ...