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][ ...
随机推荐
- 参数化SQL sql语句
在日常的数据插入时,需要避免数据脚本注入攻击,所以进行参数化SQL很有必要. --说明参数 ) --参数赋值 ' --数据插入 ,'A')
- Java-->利用文件指针分割文件
--> 大体上和字节流分割的方式没什么区别,只是加入文件指针确定要开始分割的位置... package com.dragon.java.splitmp3; import java.io.File ...
- CSS基础知识点(二)——居中
水平居中 (1) 对于块级元素,最常用的自适应水平居中为:margin:0px auto; (与 margin:auto; 效果相同) (2) 对于行内元素(a, img, input等),最常用的水 ...
- UVa 814邮件传输代理的交互
好吧,终于知道原来string有这么多用法,map可以通过vector来映射多个数 #include <iostream> #include <string> #include ...
- NOIP2016 D2T1 組合數問題(problem)
题目描述 组合数C(n,m)表示的是从n个物品中选出m个物品的方案数.举个例子,从(1,2,3) 三个物品中选择两个物品可以有(1,2),(1,3),(2,3)这三种选择方法.根据组合数的定 义,我们 ...
- Java——正则表达式(字符串操作)
public class Test1 { /* * 正则表达式:对字符串的常见操作: * 1.匹配: * 其实是用的就是string类中的matches(匹配)方法. * 2.切割 * 其实 ...
- 【转】NSString属性什么时候用copy,什么时候用strong?
原文网址:http://www.cocoachina.com/ios/20150512/11805.html 我们在声明一个NSString属性时,对于其内存相关特性,通常有两种选择(基于ARC环境) ...
- libGraphicsMagickWand.so: cannot open shared object file: No such file or directory stack traceback:
参考博文:http://www.linuxidc.com/Linux/2016-07/133213.htm ==>> Check Passed, the num of bbox and f ...
- 用js实现导航菜单点击切换选中时高亮状态
随着用户点击导航或菜单上不同的页面,出现此选项高亮显示或变为一个新的样式是经常用到的.实现它所用的原理就是通过js中的location.href得到当前页面的地址,然后在与导航上的链接地址匹对,相同的 ...
- 基于OkHttp的封装库TigerOkHttp的使用
在前面熟悉了OkHttp的用法之后,为了简化用法同时适用于我的项目,我针对OkHttp进行了更进一步的封装(源码及其Demo地址在https://github.com/huyongli/TigerOk ...