Description

1tthinking随便地画了一些圆. ftiasch认为这些圆有交集(面积非零)的可能性不大。因为他实在画了太多圆,所以你被请来判断是否存在交集。

Input

第1行,一个整数 N (1 ≤ N ≤ 105), 圆的数量。

第2到 N 行: 三个整数 Xi, Yi, Ri, 圆心在 (Xi, Yi), 半径为 Ri 的圆。

Output

如果存在面积非零的交集,则输出 "YES",否则输出 "NO"。

首先可以确定如果有相交,x坐标一定在区间[max(x[i]-r[i]),min(x[i]+r[i])]内

取这个区间中点M,在直线x=M上,若所有圆在这条线上有不为0的交集则可以判断存在面积非0的交集

否则找出一对圆在x=M上不相交,若两圆相离/相切则可以判断无解,否则把区间缩小到这两个圆交集所在的x坐标区间递归计算

每次缩小区间至少缩小一半,且圆的坐标和半径是整数,因此复杂度是可以保证的

#include<cstdio>
#include<cmath>
#include<cstdlib>
using namespace std;
typedef double ld;
const ld _0=1e-6l;
const int N=;
int n;
ld x[N],y[N],r[N];
ld L,R;
int read(){
int x=,c=getchar(),f=;
while(c>||c<){if(c=='-')f=-;c=getchar();}
while(c>&&c<)x=x*+c-,c=getchar();
return x*f;
}
void get(int id,ld X,ld&a,ld&b){
X-=x[id];
X=sqrt(r[id]*r[id]-X*X);
a=y[id]-X;
b=y[id]+X;
}
bool chk(ld X,int a,int b){
if(fabs(X-x[a])>r[a]||fabs(X-x[b])>r[b])return ;
ld a1,a2,b1,b2;
get(a,X,a1,a2);
get(b,X,b1,b2);
return a2>b1&&a1<b2;
}
void chk(int a,int b){
ld xd=x[b]-x[a],yd=y[b]-y[a];
ld d=sqrt(xd*xd+yd*yd);
if(d+_0>r[a]+r[b]){
puts("NO");
exit();
}
ld s=(r[a]+r[b]+d)/.;
ld h=*sqrt(s*(s-r[a])*(s-r[b])*(s-d))/d;
ld m=x[a]+xd*sqrt(r[a]*r[a]-h*h)/d,c=h*fabs(yd)/d;
if(d*d+r[a]*r[a]<r[b]*r[b])m=x[a]*-m;
ld lx=m-c,rx=m+c;
if(lx>x[a]-r[a]&&chk(x[a]-r[a]+_0,a,b))lx=x[a]-r[a];
if(lx>x[b]-r[b]&&chk(x[b]-r[b]+_0,a,b))lx=x[b]-r[b];
if(rx<x[a]+r[a]&&chk(x[a]+r[a]-_0,a,b))rx=x[a]+r[a];
if(rx<x[b]+r[b]&&chk(x[b]+r[b]-_0,a,b))rx=x[b]+r[b];
if(lx>L)L=lx;
if(rx<R)R=rx;
}
int main(){
n=read();
for(int i=;i<n;i++){
x[i]=read();
y[i]=read();
r[i]=read();
}
L=x[]-r[],R=x[]+r[];
for(int i=;i<n;i++){
if(L<x[i]-r[i])L=x[i]-r[i];
if(R>x[i]+r[i])R=x[i]+r[i];
}
while(){
if(L+_0>R){
puts("NO");
return ;
}
ld M=(L+R)/.;
ld y1,y2,a1,a2;
get(,M,y1,y2);
for(int i=;i<n;i++){
get(i,M,a1,a2);
if(a1>y1)y1=a1;
if(a2<y2)y2=a2;
if(y1+_0>y2){
for(int j=;j<i;j++){
get(j,M,y1,y2);
if(y1>=a2-_0||y2<=a1+_0){
chk(i,j);
goto re;
}
}
}
}
puts("YES");
return ;
re:;
}
}

bzoj2289: 【POJ Challenge】圆,圆,圆的更多相关文章

  1. bzoj 2295: 【POJ Challenge】我爱你啊

    2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec  Memory Limit: 128 MB Description ftiasch是个十分受女生欢迎的同学,所以 ...

  2. 【链表】BZOJ 2288: 【POJ Challenge】生日礼物

    2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 382  Solved: 111[Submit][S ...

  3. BZOJ2288: 【POJ Challenge】生日礼物

    2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 284  Solved: 82[Submit][St ...

  4. BZOJ2293: 【POJ Challenge】吉他英雄

    2293: [POJ Challenge]吉他英雄 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 80  Solved: 59[Submit][Stat ...

  5. BZOJ2287: 【POJ Challenge】消失之物

    2287: [POJ Challenge]消失之物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 254  Solved: 140[Submit][S ...

  6. BZOJ2295: 【POJ Challenge】我爱你啊

    2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 126  Solved: 90[Submit][Sta ...

  7. BZOJ2296: 【POJ Challenge】随机种子

    2296: [POJ Challenge]随机种子 Time Limit: 1 Sec  Memory Limit: 128 MBSec  Special JudgeSubmit: 114  Solv ...

  8. BZOJ2292: 【POJ Challenge 】永远挑战

    2292: [POJ Challenge ]永远挑战 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 513  Solved: 201[Submit][ ...

  9. BZOJ 2287: 【POJ Challenge】消失之物( 背包dp )

    虽然A掉了但是时间感人啊.... f( x, k ) 表示使用前 x 种填满容量为 k 的背包的方案数, g( x , k ) 表示使用后 x 种填满容量为 k 的背包的方案数. 丢了第 i 个, 要 ...

  10. 2292: 【POJ Challenge 】永远挑战

    2292: [POJ Challenge ]永远挑战 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 553  Solved: 230[Submit][ ...

随机推荐

  1. eclipse ERROR: Unable to add module to the current project as it is not of ...

    原因: Workspace下放了个POM文件,造成了M2eclipse插件的误解. 解决方案: 删掉就OK了.

  2. 纯代码写UI的时候,如何指定style?

    有的时候,需要使用纯代码实现Android UI,那么这个时候如何指定某个UI组件的样式呢? 一般来说,UI组件都有一些set方法可供使用,以调整一些UI属性,从而达到调整样式的目的. 但是,情况并非 ...

  3. Particles.js基于Canvas画布创建粒子原子颗粒效果

    文章目录 使用方法 自定义参数 相关链接 Particles.js是一款基于HTML5 Canvas画布的轻量级粒子动画插件,可以设置粒子的形状.旋转.分布.颜色等属性,还可以动态添加粒子,效果非常炫 ...

  4. python 数据结构之双向链表的实现

    和单链表类似,只不过是增加了一个指向前面一个元素的指针而已. 示意图: python 实现代码: #!/usr/bin/python # -*- coding: utf-8 -*- class Nod ...

  5. 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) G 优先队列

    G. Car Repair Shop time limit per test 2 seconds memory limit per test 512 megabytes input standard ...

  6. web标准的可用性和可访问性

    在Web前端开发界,有三个词经常被提及:可用性(Usability).可访问性(Accessibility)和可维护性(Maintainability). 可用性指的是:产品是否容易上手,用户能否完成 ...

  7. RViz 实时观测机器人建立导航2D封闭空间地图过程 (SLAM) ----27

    原创博客:转载请表明出处:http://www.cnblogs.com/zxouxuewei/ ROS提供了非常强大的图形化模拟环境 RViz,这个 RViz 能做的事情非常多.今天我们学习一下如何使 ...

  8. activiti 任务节点 处理人设置【转】

    转自http://blog.csdn.net/qq_30739519/article/details/51225067 1.1.1. 前言 分享牛原创(尊重原创 转载对的时候第一行请注明,转载出处来自 ...

  9. timus 1022 Genealogical Tree(拓扑排序)

    Genealogical Tree Time limit: 1.0 secondMemory limit: 64 MB Background The system of Martians’ blood ...

  10. 了解CentOS及周边

    CentOS相关介绍 CentOS是Community ENTerprise Operating System的简称RHEL的全称则是Red Hat Enterprise LinuxFedoro Co ...