题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2819

题目意思:

给了平面上的n条线段:

让你在x轴上[0,L]的范围内找一个点作为圆心,画一个圆,这个圆不能把线段包含在里面去。

求最大的半径。

求解:

二分最终的答案,求解。

对于二分的半径值,对每条线段找出对于x位置上满足半径要求的段。

看n条线段有没有交集就可以了。

 /* ***********************************************
Author :kuangbin
Created Time :2014/5/10 23:18:09
File Name :E:\2014ACM\区域赛练习\2010\2010SouthEastern_European_Region\C.cpp
************************************************ */ #include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std; const double eps = 1e-;
const double inf = 1e5;
const double pi = acos(-1.0);
int sgn(double x)
{
if(fabs(x) < eps)return ;
else if(x < )return -;
return ;
}
struct Point
{
double x,y;
Point(){}
Point(double _x,double _y)
{
x = _x;
y = _y;
}
void input()
{
scanf("%lf%lf",&x,&y);
}
Point operator -(const Point &b)const
{
return Point(x-b.x,y-b.y);
}
double operator *(const Point &b)const
{
return x*b.x + y*b.y;
}
double operator ^(const Point &b)const
{
return x*b.y - y*b.x;
}
double len()
{
return hypot(x,y);
}
double distance(Point p)
{
return hypot(x-p.x,y-p.y);
}
};
struct Line
{
Point s,e;
Line(){}
Line(Point _s,Point _e)
{
s = _s;
e = _e;
}
void input()
{
s.input();
e.input();
}
double length()
{
return s.distance(e);
}
double dispointtoline(Point p)
{
return fabs((p-s)^(e-s))/length();
}
double dispointtoseg(Point p)
{
if(sgn((p-s)*(e-s)) < || sgn((p-e)*(s-e)) < )
return min(p.distance(s),p.distance(e));
return dispointtoline(p);
}
};
const int MAXN = ;
Line line[MAXN]; double get(int i,double L)
{
double l = , r = L;
while(r - l >= eps)
{
double mid = (l + r)/;
double midmid = (r + mid)/;
if(line[i].dispointtoseg(Point(mid,)) < line[i].dispointtoseg(Point(midmid,)))
r = midmid - eps;
else l = mid + eps;
}
return l;
}
int n;
double L; struct Node
{
double a;
int c;
Node(double _a = ,int _c = )
{
a = _a;
c = _c;
}
};
bool cmp(Node a,Node b)
{
if(sgn(a.a - b.a) != )return a.a < b.a;
else return a.c > b.c;
} double bin1(int i,double l,double r,double R)
{
while(r-l >= eps)
{
double mid = (l+r)/;
if(line[i].dispointtoseg(Point(mid,)) <= R)
r = mid - eps;
else l = mid + eps;
}
return l;
}
double bin2(int i,double l,double r,double R)
{
while(r-l >= eps)
{
double mid = (l+r)/;
if(line[i].dispointtoseg(Point(mid,)) <= R)
l = mid + eps;
else r = mid - eps;
}
return l;
} bool gao(double r)
{
vector<Node>vec;
for(int i = ;i < n;i++)
{
double tmp = get(i,L);
if(sgn(line[i].dispointtoseg(Point(tmp,)) - r) >= )
{
vec.push_back(Node(,));
vec.push_back(Node(L,-));
continue;
}
if(sgn(line[i].dispointtoseg(Point(,)) - r) >= )
{
double tt = bin1(i,,tmp,r);
vec.push_back(Node(,));
vec.push_back(Node(tt,-));
}
if(sgn(line[i].dispointtoseg(Point(L,)) - r) >= )
{
double tt = bin2(i,tmp,L,r);
vec.push_back(Node(tt,));
vec.push_back(Node(L,-));
}
}
sort(vec.begin(),vec.end(),cmp);
int cnt = ;
for(int i = ;i < vec.size();i++)
{
cnt += vec[i].c;
if(cnt >= n)return true;
}
return false;
} double solve()
{
double l = , r = inf;
while(r-l >= eps)
{
double mid = (l+r)/;
if(gao(mid))l = mid+eps;
else r = mid - eps;
}
return l;
} int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d%lf",&n,&L);
for(int i = ;i < n;i++)
line[i].input();
printf("%.3lf\n",solve());
}
return ;
}

UVALive 4818 - Largest Empty Circle on a Segment (计算几何)的更多相关文章

  1. 4818 Largest Empty Circle on a Segment (几何+二分)

    ACM-ICPC Live Archive 挺水的一道题,直接二分圆的半径即可.1y~ 类似于以前半平面交求核的做法,假设半径已经知道,我们只需要求出线段周围哪些位置是不能放置圆心的即可.这样就转换为 ...

  2. uva 1463 - Largest Empty Circle on a Segment(二分+三分+几何)

    题目链接:uva 1463 - Largest Empty Circle on a Segment 二分半径,对于每一个半径,用三分求出线段到线段的最短距离,依据最短距离能够确定当前R下每条线段在[0 ...

  3. Visulalize Boost Voronoi in OpenSceneGraph

    Visulalize Boost Voronoi in OpenSceneGraph eryar@163.com Abstract. One of the important features of ...

  4. Voronoi Diagram——维诺图

    Voronoi图定义   任意两点p 和q 之间的欧氏距离,记作 dist(p, q) .就平面情况而言,我们有           dist(p, q) =  (px-qx)2+ (py-qy)2 ...

  5. Apache Kafka – KIP 32,33 Time Index

    32, 33都是和时间相关的, KIP-32 - Add timestamps to Kafka message 引入版本,0.10.0.0 需要给kafka的message加上时间戳,这样更方便一些 ...

  6. 杭电ACM分类

    杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...

  7. 转载:hdu 题目分类 (侵删)

    转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...

  8. BUAA_2020_软件工程_结对项目作业

    项目 内容 这个作业属于哪个课程 班级博客 这个作业的要求在哪里 作业要求 我在这个课程的目标是 掌握软件工程的思路方法 这个作业在哪个具体方面帮助我实现目标 学习结对编程 教学班级 006 项目地址 ...

  9. zw版_zw中文增强版Halcon官方Delphi例程

    [<zw版·delphi与halcon系列原创教程>zw版_zw中文增强版Halcon官方Delphi例程 源码下载:http://files.cnblogs.com/files/ziwa ...

随机推荐

  1. unique函数的作用

    unique() 去重函数 unique()函数是一个去重函数,STL中unique的函数 unique的功能是去除相邻的重复元素(只保留一个),还有一个容易忽视的特性是它并不真正把重复的元素删除.他 ...

  2. JavaSE坦克网络版

    02.1.建立Server(保持这个TankServer一直运行) package server; public class TankServer { public static void main( ...

  3. Android项目的目录结构

    assets  资产目录,  存放一个文件的 这个文件会被打包到应用程序的apk(安装包 ) bin 编译后的文件目录 gen 自动生成文件的目录 roject.properties 代表编译的版本  ...

  4. 认识CPU Cache

    http://geek.csdn.net/news/detail/114619 7个示例科普CPU Cache:http://coolshell.cn/articles/10249.html Linu ...

  5. javascript 中的 true 或 false

    JavaScript中奇葩的假值 通常在以下语句结构中需要判断真假 if分支语句 while循环语句 for里的第二个语句 如 1 2 3 4 5 6 7 if (boo) { // do somet ...

  6. Angular1.x组件通讯方式总结

    Angular1开发模式 这里需要将Angular1分为Angular1.5之前和Angular1.5两个不同的阶段来讲,两者虽然同属Angular1,但是在开发模式上还是有较大区别的.在Angula ...

  7. CSS 分组

    选择器分组 假设希望 h2 元素和段落都有灰色.为达到这个目的,最容易的做法是使用以下声明: h2, p {color:gray;} 将 h2 和 p 选择器放在规则左边,然后用逗号分隔,就定义了一个 ...

  8. phoenix与spark整合

    目的是将phoenix做存储,spark做计算层.这样就结合了phoenix查询速度快和spark计算速度快的优点.在这里将Phoenix的表作为spark的RDD或者DataFrames来操作,并且 ...

  9. Lucene/Solr搜索引擎开发笔记 - 第2章 Solr安装与部署(Tomcat篇)

    一.安装环境 图1-1 Tomcat和Solr的版本 我本机目前使用的Java版本为JDK 1.8,因为Solr 4.9要求Java版本为1.7+,请注意. 二.Solr部署到Tomcat流程 图1- ...

  10. 深入浅出WPF开发下载

    ​为什么要学习WPF? 许多朋友也许会问:既然表示层技术那么多,为什么还要推出WPF作为表示层技术呢?我们话精力学习WPF有什么收益和好处呢,这个问题我们从两个方面进行回答. 首先,只要开发表示层程序 ...