UVALive 4818 - Largest Empty Circle on a Segment (计算几何)
题目链接: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 (计算几何)的更多相关文章
- 4818 Largest Empty Circle on a Segment (几何+二分)
ACM-ICPC Live Archive 挺水的一道题,直接二分圆的半径即可.1y~ 类似于以前半平面交求核的做法,假设半径已经知道,我们只需要求出线段周围哪些位置是不能放置圆心的即可.这样就转换为 ...
- uva 1463 - Largest Empty Circle on a Segment(二分+三分+几何)
题目链接:uva 1463 - Largest Empty Circle on a Segment 二分半径,对于每一个半径,用三分求出线段到线段的最短距离,依据最短距离能够确定当前R下每条线段在[0 ...
- Visulalize Boost Voronoi in OpenSceneGraph
Visulalize Boost Voronoi in OpenSceneGraph eryar@163.com Abstract. One of the important features of ...
- Voronoi Diagram——维诺图
Voronoi图定义 任意两点p 和q 之间的欧氏距离,记作 dist(p, q) .就平面情况而言,我们有 dist(p, q) = (px-qx)2+ (py-qy)2 ...
- Apache Kafka – KIP 32,33 Time Index
32, 33都是和时间相关的, KIP-32 - Add timestamps to Kafka message 引入版本,0.10.0.0 需要给kafka的message加上时间戳,这样更方便一些 ...
- 杭电ACM分类
杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...
- 转载:hdu 题目分类 (侵删)
转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...
- BUAA_2020_软件工程_结对项目作业
项目 内容 这个作业属于哪个课程 班级博客 这个作业的要求在哪里 作业要求 我在这个课程的目标是 掌握软件工程的思路方法 这个作业在哪个具体方面帮助我实现目标 学习结对编程 教学班级 006 项目地址 ...
- zw版_zw中文增强版Halcon官方Delphi例程
[<zw版·delphi与halcon系列原创教程>zw版_zw中文增强版Halcon官方Delphi例程 源码下载:http://files.cnblogs.com/files/ziwa ...
随机推荐
- iOS9适配中的各种问题
1.http在ios9上不能在使用.需要进行配置. the resource could not be loaded because the app transport security policy ...
- ORACLE PL/SQL编程详解
ORACLE PL/SQL编程详解 编程详解 SQL语言只是访问.操作数据库的语言,并不是一种具有流程控制的程序设计语言,而只有程序设计语言才能用于应用软件的开发.PL /SQL是一种高级数据库程序设 ...
- CSS 知识点
1:display:block:比较常用于<a><span>这两个标签——因为这两个标签非块元素,如果不用display:block定义一下,因为a标签没有结构,就是没有宽高, ...
- ADF_Starting系列9_使用EJB/JPA/JSF通过ADF构建Web应用程序之测试J2EE Container
2013-05-01 Created By BaoXinjian
- VS2010 + Entity FrameWork 4.4 +Mvc 4.0 出现的错误
Compiler Error Message: CS0012: The type 'System.Data.Objects.DataClasses.EntityObject' is defined i ...
- 随笔 高质量 C++/C 编程指南
内存分配方式有三种:) 从静态存储区域分配.内存在程序编译的时候就已经分配好,这块内存在程序的整个运行期间都存在.例如全局变量, static 变量.) 在栈上创建.在执行函数时,函数内局部变量的存储 ...
- jQuery MiniUI 开发指南+API组件参考手册
jQuery MiniUI 开发指南 本文档将逐步的讲解jQuery MiniUI的方方面面,从此您将踏上jQuery MiniUI的深入探索之旅. 1.Hello M ...
- Symfony2 资料篇
http://www.chrisyue.com/symfony2-in-action-day-1.html 由于Symfony2现在还没有很完善的中文文档,所以不想看文档的同学可以直接进行点击上面的链 ...
- COSBench添加driver负载机
说明:Driver是COSBench测试工具中对负载机的一种标记,相当于loadrunner中的负载发生器. 在使用COSBench进行云存储性能测试时,面对强大的云服务,如果只有单个driver负载 ...
- NHibernate系列文章十二:Load/Get方法
摘要 NHibernate提供两个方法按主键值查找对象:Load/Get. 1. Load/Get方法的区别 Load: Load方法可以对查询进行优化. Load方法实际得到一proxy对象,并不立 ...