【CF887E】Little Brother

题意:给你n个圆和一条线段,保证圆和圆、圆和线段所在直线不相交,不相切,不包含。求一个过线段两端点的圆,满足不和任何圆相交(可以相切、包含)。问圆的最小半径。

n<=100000

题解:比较显然的二分题。由于新圆的半径一定在线段的中垂线上,且距离越远半径越大。那么问题就变成了最小化半径到线段的距离。

不难发现,对于每个圆来说,如果新圆不和它相交,那么半径所在的区域会被限定在$(-\infty,a]\bigcup[b,\infty)$里。a和b我们可以通过二分求得。最后用扫描线统计出所有合法的半径区间,并更新答案即可。

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
const int maxn=100010;
struct point
{
double x,y;
point() {}
point(double a,double b) {x=a,y=b;}
point operator + (const point &a) const {return point(x+a.x,y+a.y);}
point operator - (const point &a) const {return point(x-a.x,y-a.y);}
point operator * (const double &a) const {return point(x*a,y*a);}
double operator * (const point &a) const {return x*a.y-y*a.x;}
}A,B,P,C,D,O,K,K1;
int n,m,sum;
double R,ans;
struct node
{
double x; int k;
node() {}
node(double a,int b) {x=a,k=b;}
}q[maxn<<1];
inline double dis(point a) {return sqrt(a.x*a.x+a.y*a.y);}
inline int rd()
{
int ret=0,f=1; char gc=getchar();
while(gc<'0'||gc>'9') {if(gc=='-') f=-f; gc=getchar();}
while(gc>='0'&&gc<='9') ret=ret*10+(gc^'0'),gc=getchar();
return ret*f;
}
bool cmp(const node &a,const node &b)
{
return a.x<b.x;
}
int main()
{
double l,r,mid;
A.x=rd(),A.y=rd(),B.x=rd(),B.y=rd(),n=rd(),C=(A+B)*0.5,K=B-A;
K=K*(1.0/dis(K)),K1=point(-K.y,K.x);
int i,j,flag;
for(i=1;i<=n;i++)
{
P.x=rd(),P.y=rd(),R=rd();
flag=((P-A)*(B-P)>0);
l=-1e12,r=1e12;
for(j=1;j<=80;j++)
{
mid=(l+r)/2,O=C+(K1*mid);
if((dis(P-O)>dis(A-O)+R)^flag) l=mid;
else r=mid;
}
q[++m]=node(l,flag?-1:1);
l=-1e12,r=1e12;
for(j=1;j<=80;j++)
{
mid=(l+r)/2,O=C+(K1*mid);
if((dis(A-O)>dis(P-O)+R)^flag) r=mid;
else l=mid;
}
q[++m]=node(r,flag?1:-1);
}
q[++m]=node(1e12,0),q[++m]=node(-1e12,0),q[++m]=node(0,0);
sort(q+1,q+m+1,cmp);
ans=1e12;
for(flag=0,i=1;i<=m;i++)
{
if(!sum) flag=1,ans=min(ans,fabs(q[i].x));
sum+=q[i].k;
if(!sum) flag=1,ans=min(ans,fabs(q[i].x));
}
if(!flag) puts("-1");
else O=C+(K1*ans),printf("%.10lf",dis(A-O));
return 0;
}//2 4 7 13 3 3 0 1 12 4 2 -4 14 2

【CF887E】Little Brother 二分+几何的更多相关文章

  1. hdu 4033 二分几何

    参考:http://blog.csdn.net/libin56842/article/details/26618129 题意:给一个正多边形内点到其他顶点的距离(逆时针给出),求正多边形的边长 二分多 ...

  2. 二分法 (UVA10668 Expanding Rods)(二分+几何)

    转载请注明出处:優YoU http://user.qzone.qq.com/289065406/blog/1301845324 大致题意: 一根两端固定在两面墙上的杆 受热弯曲后变弯曲.求前后两个状态 ...

  3. Incircle and Circumcircle(二分+几何)浙大月赛zoj3806(详解版)图

    Incircle and Circumcircle Time Limit: 2 Seconds Memory Limit: 65536 KB Special Judge A triangle is o ...

  4. 【CF744D】Hongcow Draws a Circle 二分+几何

    [CF744D]Hongcow Draws a Circle 题意:给你平面上n个红点和m个蓝点,求一个最大的圆,满足圆内不存在蓝点,且至少包含一个红点. $n,m\le 10^3$ 题解:我们先不考 ...

  5. Codeforces Round #409 (rated, Div. 2, based on VK Cup 2017 Round 2) A B C D 暴力 水 二分 几何

    A. Vicious Keyboard time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  6. 【BZOJ3007】拯救小云公主 二分+几何+对偶图

    [BZOJ3007]拯救小云公主 Description     英雄又即将踏上拯救公主的道路……     这次的拯救目标是——爱和正义的小云公主.     英雄来到boss的洞穴门口,他一下子就懵了 ...

  7. POJ 1905 题解(二分+几何)

    题面 传送门 分析 如图:已知AB=L,弧AB=L(1+nC)" role="presentation" style="position: relative;& ...

  8. poj 1905Expanding Rods

    /* 二分 + 几何 弧长L, 圆半径R, 弧度 q, L=R*q; 二分: 弧度(0~PI) 或者 高度(L/2~L) */ #include<cstdio> #include<i ...

  9. SDU暑假排位第一场 (Gym - 100889)

    啊今天有点挂机啊 D题和队友暴力后发现一组数据跑得飞快 然后遇上1e5组数据就没了..... 然后我疯狂优化暴力 然后去世了 最后半小时F也没写出来 主要还是最后有点慌并且没有考虑清楚 导致情况越写越 ...

随机推荐

  1. [转]Linux内核源码详解--iostat

    Linux内核源码详解——命令篇之iostat 转自:http://www.cnblogs.com/york-hust/p/4846497.html 本文主要分析了Linux的iostat命令的源码, ...

  2. 【matlab】=size(img)的其中两种用法&zeros( )

    i1=imread('D:\Work\1.png'); i1=rgb2gray(i1); [m,n]=size(i1); 返回图片的尺寸信息, 并存储在m.n中.其中m中存储的是行数,n中存储的是列数 ...

  3. Python+Django(Python Web项目初体验)

    参考:https://blog.csdn.net/qq_34081993/article/details/79229784 Django是一个开放源代码的Web应用框架,由Python写成. 安装Dj ...

  4. 5种实现垂直居中css

    摘要: 在我们制作页面的时候经常会遇到内容垂直居中的需求,今天分享5种垂直居中的方法,每种方法都有自己的优缺点,可以选择自己喜欢的方式.以下代码都经过本人亲自测试. line-height: < ...

  5. Metropolis-Hastings算法

    (学习这部分内容大约需要1.5小时) 摘要 马尔科夫链蒙特卡洛(Markov chain Monte Carlo, MCMC)是一种近似采样算法, 它通过定义稳态分布为 \(p\) 的马尔科夫链, 在 ...

  6. EditDistance,求两个字符串最小编辑距离,动态规划

    问题描述: 题目描述Edit DistanceGiven two words word1 and word2, find the minimum number of steps required to ...

  7. Java 代码块:静态代码块、构造代码块、构造函数块

    Class : StaticFa package edu.bai.du.lime.staticCode; public class StaticFa { // 随着类的声明而执行 static { S ...

  8. webApi之FromUri和FromBody区别

    public Link GetLink([FromUri] FileRequest fileRequest) { if (ModelState.IsValid) { var xml = WebConf ...

  9. 线程同步 –AutoResetEvent和ManualResetEvent

    上一篇介绍了通过lock关键字和Monitor类型进行线程同步,本篇中就介绍一下通过同步句柄进行线程同步. 在Windows系统中,可以使用内核对象进行线程同步,内核对象由系统创建并维护.内核对象为内 ...

  10. mysql字段集合中如何去除其中一个元素

    在一对多方案中,我们用逗号拼接进行存储,避免存储多条,或者分表,那么此时出现了存储上如果需要修改的话 就带来了难度,比如规则记录表如下 如果2号规则被删除,那么这张表的所有有2的记录也要被清除掉,此时 ...