bzoj2289: 【POJ Challenge】圆,圆,圆
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】圆,圆,圆的更多相关文章
- bzoj 2295: 【POJ Challenge】我爱你啊
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec Memory Limit: 128 MB Description ftiasch是个十分受女生欢迎的同学,所以 ...
- 【链表】BZOJ 2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 382 Solved: 111[Submit][S ...
- BZOJ2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 284 Solved: 82[Submit][St ...
- BZOJ2293: 【POJ Challenge】吉他英雄
2293: [POJ Challenge]吉他英雄 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 80 Solved: 59[Submit][Stat ...
- BZOJ2287: 【POJ Challenge】消失之物
2287: [POJ Challenge]消失之物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 254 Solved: 140[Submit][S ...
- BZOJ2295: 【POJ Challenge】我爱你啊
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 126 Solved: 90[Submit][Sta ...
- BZOJ2296: 【POJ Challenge】随机种子
2296: [POJ Challenge]随机种子 Time Limit: 1 Sec Memory Limit: 128 MBSec Special JudgeSubmit: 114 Solv ...
- BZOJ2292: 【POJ Challenge 】永远挑战
2292: [POJ Challenge ]永远挑战 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 513 Solved: 201[Submit][ ...
- BZOJ 2287: 【POJ Challenge】消失之物( 背包dp )
虽然A掉了但是时间感人啊.... f( x, k ) 表示使用前 x 种填满容量为 k 的背包的方案数, g( x , k ) 表示使用后 x 种填满容量为 k 的背包的方案数. 丢了第 i 个, 要 ...
- 2292: 【POJ Challenge 】永远挑战
2292: [POJ Challenge ]永远挑战 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 553 Solved: 230[Submit][ ...
随机推荐
- 使用使用for in 语句,并对数组中元素进行了增删操作,报错却不知怎么办?
解决方案: 在forin遍历过程中不要对遍历数据进行修改, for in 的时候如果在操作内移除会打乱 他的count 导致出错,如果要修改尽量用for循环
- Apache HttpClient使用之阻塞陷阱
前言: 之前做个一个数据同步的定时程序. 其内部集成了某电商的SDK(简单的Apache Httpclient4.x封装)+Spring Quartz来实现. 原本以为简单轻松, 喝杯咖啡就高枕无忧的 ...
- clipToBounds
最近在开发H5平台的iOS移动侧,遇到些问题,随手记录下来. 1 UIView的clipToBounds 窗口裁剪,默认是NO,表示如果父窗口的大小已经不足以显示子窗口,也不进行裁剪,而是显示,但这时 ...
- Jquery图片上传预览效果
uploadPreview.js jQuery.fn.extend({ uploadPreview: function (opts) { var _self = this, _this = $(thi ...
- hdu1114 Piggy-Bank ——完全背包
link:http://acm.hdu.edu.cn/showproblem.php?pid=1114 只不过求得是最小值.没什么可说的,连我都会做……o(╯□╰)o /* ID: zypz4571 ...
- Qt 串口学习3
1.怎样将选择波特率 1)使用if else 的方法 if(ui->BaudRate->currentText()==tr("9600")) //根据组合框 ...
- URAL 1934 Black Spot(最短路)
Black Spot Time limit: 1.0 secondMemory limit: 64 MB Bootstrap: Jones's terrible leviathan will find ...
- Latex 编译错误: ! pdfTeX error (ext4): \pdfendlink ended up in different nesting level than \pd fstartlink. 解决方法
最近写 AAAI 的文章,下载了其模板,但是蛋疼的是,总是提示错误,加上参考文献总是出错: 如下: ! pdfTeX error (ext4): \pdfendlink ended up in dif ...
- http://www.allthingsdistributed.com
http://www.allthingsdistributed.com159-6289-2518
- form表单回车提交问题,JS监听回车事件
我们有时候希望回车键敲在文本框(input element)里来提交表单(form),但有时候又不希望如此.比如搜索行为,希望输入完关键词之后直接按回车键立即提交表单,而有些复杂表单,可能要避免回车键 ...