http://poj.org/problem?id=3525

给出一个凸包,要求凸包内距离所有边的长度的最小值最大的是哪个

思路:二分答案,然后把凸包上的边移动这个距离,做半平面交看是否有解。

#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
const double finf=1e10;
const double eps=1e-;
const double Pi=acos(-);
int n,tot;
struct Point{
double x,y;
Point(){}
Point(double x0,double y0):x(x0),y(y0){}
}p[];
struct Line{
Point s,e;
double slop;
Line(){}
Line(Point s0,Point e0):s(s0),e(e0){}
}l[],L[],c[];
int read(){
int t=,f=;char ch=getchar();
while (ch<''||ch>''){if (ch=='-')f=-;ch=getchar();}
while (''<=ch&&ch<=''){t=t*+ch-'';ch=getchar();}
return t*f;
}
Point operator *(Point p,double x){
return Point(p.x*x,p.y*x);
}
Point operator /(Point p,double x){
return Point(p.x/x,p.y/x);
}
double operator *(Point p1,Point p2){
return p1.x*p2.y-p1.y*p2.x;
}
Point operator -(Point p1,Point p2){
return Point(p1.x-p2.x,p1.y-p2.y);
}
Point operator +(Point p1,Point p2){
return Point(p1.x+p2.x,p1.y+p2.y);
}
double sqr(double x){
return x*x;
}
double dis(Point p){
return sqrt(sqr(p.x)+sqr(p.y));
}
Point e(Point p){
double len=dis(p);
p=p/len;
return p;
}
Point turn(Point p,double x){
double Sin=sin(x),Cos=cos(x);
double X=Cos*p.x-Sin*p.y;
double Y=Cos*p.y+Sin*p.x;
return Point(X,Y);
}
bool cmp(Line p1,Line p2){
if (p1.slop!=p2.slop) return p1.slop<p2.slop;
else return (p1.e-p1.s)*(p2.e-p1.s)<=;
}
void build(double mid){
for (int i=;i<=tot;i++){
Point p=e(turn(l[i].e-l[i].s,Pi/2.0))*mid;
L[i].s=l[i].s+p;
L[i].e=l[i].e+p;
}
for (int i=;i<=tot;i++)
L[i].slop=l[i].slop;
std::sort(L+,L++tot,cmp);
}
Point inter(Line p1,Line p2){
double k1=(p2.e-p1.s)*(p1.e-p1.s);
double k2=(p1.e-p1.s)*(p2.s-p1.s);
double t=(k2/(k1+k2));
double x=p2.s.x+(p2.e.x-p2.s.x)*t;
double y=p2.s.y+(p2.e.y-p2.s.y)*t;
return Point(x,y);
}
bool jud(Line p1,Line p2,Line p3){
Point p=inter(p1,p2);
return (p-p3.s)*(p3.e-p3.s)>;
}
bool phi(){
int cnt=;
for (int i=;i<=tot;i++)
if (L[i].slop!=L[i-].slop) L[++cnt]=L[i];
int lll=,rrr=;c[lll]=L[];c[rrr]=L[];
for (int i=;i<=cnt;i++){
while (lll<rrr&&jud(c[rrr],c[rrr-],L[i])) rrr--;
while (lll<rrr&&jud(c[lll],c[lll+],L[i])) lll++;
c[++rrr]=L[i];
}
while (lll<rrr&&jud(c[rrr],c[rrr-],c[lll])) rrr--;
while (lll<rrr&&jud(c[lll],c[lll+],c[rrr])) lll++;
if (rrr-lll+>=) return ;
else return ;
}
bool check(double mid){
build(mid);
if (phi()) return ;
return ;
}
int main(){
while (scanf("%d",&n)!=EOF){
if (n==) return ;
for (int i=;i<=n;i++)
p[i].x=read(),p[i].y=read();
p[n+]=p[];
tot=;
for (int i=;i<=n;i++)
l[++tot]=Line(p[i],p[i+]);
for (int i=;i<=tot;i++) l[i].slop=atan2(l[i].e.y-l[i].s.y,l[i].e.x-l[i].s.x);
double ll=0.0,rr=finf;
while (rr-ll>eps){
double mid=(ll+rr)/2.0;
if (check(mid)) ll=mid;
else rr=mid;
}
printf("%.6f\n",ll);
}
}

POJ 3525 Most Distant Point from the Sea的更多相关文章

  1. POJ 3525 Most Distant Point from the Sea [半平面交 二分]

    Most Distant Point from the Sea Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 5153   ...

  2. POJ 3525 Most Distant Point from the Sea (半平面交+二分)

    Most Distant Point from the Sea Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 3476   ...

  3. POJ 3525 Most Distant Point from the Sea (半平面交)

    Description The main land of Japan called Honshu is an island surrounded by the sea. In such an isla ...

  4. POJ 3525 Most Distant Point from the Sea (半平面交向内推进+二分半径)

    题目链接 题意 : 给你一个多边形,问你里边能够盛的下的最大的圆的半径是多少. 思路 :先二分半径r,半平面交向内推进r.模板题 #include <stdio.h> #include & ...

  5. POJ 3525 Most Distant Point from the Sea 二分+半平面交

    题目就是求多变形内部一点. 使得到任意边距离中的最小值最大. 那么我们想一下,可以发现其实求是看一个圆是否能放进这个多边形中. 那么我们就二分这个半径r,然后将多边形的每条边都往内退r距离. 求半平面 ...

  6. 【POJ】【3525】Most Distant Point from the Sea

    二分+计算几何/半平面交 半平面交的学习戳这里:http://blog.csdn.net/accry/article/details/6070621 然而这题是要二分长度r……用每条直线的距离为r的平 ...

  7. POJ 3525/UVA 1396 Most Distant Point from the Sea(二分+半平面交)

    Description The main land of Japan called Honshu is an island surrounded by the sea. In such an isla ...

  8. poj 3525 凸多边形多大内切圆

    Most Distant Point from the Sea Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 4758   ...

  9. LA 3890 Most Distant Point from the Sea(半平面交)

    Most Distant Point from the Sea [题目链接]Most Distant Point from the Sea [题目类型]半平面交 &题解: 蓝书279 二分答案 ...

随机推荐

  1. 抛出异常的区别 throw 和throw ex

    在面试的过程中提到了异常捕获的的几种用法,之前一直使用但是没有仔细留意,调试程序的过程中发现还是有区别的,主要区别在堆栈信息的起始点不同,下边我们通过实例来看这集中不同的抛出异常的方法. 一般我们推荐 ...

  2. hdu3534,个人认为很经典的树形dp

    题目大意为,求一个树的直径(最长路),以及直径的数量 朴素的dp只能找出某点开始的最长路径,但这个最长路径却不一定是树的直径,本弱先开始就想简单了,一直wa 直到我看了某位大牛的题解... 按照那位大 ...

  3. [置顶] ARM指令集和常用寄存器

    1) ARM指令集 32位的 ARM指令和 16位 的Thumb指令 1,寄存器寻址 MOV R1, R2  //将寄存器R2的值传给寄存器R1 2,立即寻址 MOV R0, #0XFF00 //数据 ...

  4. Selenium2(webdriver)入门之TestNG的使用

    一.在Eclipse中安装TestNG 1.打开eclipse-->help-->Install New Software-->Add,输入Name和Location后,点击OK. ...

  5. LIB文件和DLL文件的作用

    (1)lib是编译时需要的,dll是运行时需要的.如果要完成源代码的编译,有lib就够了.如果也使动态连接的程序运行起来,有dll就够了.在开发和调试阶段,当然最好都有.(2)一般的动态库程序有lib ...

  6. RPC 实现

    PC,即 Remote Procedure Call(远程过程调用),说得通俗一点就是:调用远程计算机上的服务,就像调用本地服务一样. RPC 可基于 HTTP 或 TCP 协议,Web Servic ...

  7. Cycling Label

    Cycling Label 来源: github/BBCyclingLabel Licence: Apache 2.0 作者: Bruno de Carvalho 分类: 标签(Label) 平台: ...

  8. DataTables 配置和使用

    WEB后台开发,如果用的是Bootstrap框架,那这个表格神器你一定不要错过. 官方地址:https://datatables.net/ What?英文不好,没关系咱有中文的 http://data ...

  9. vim的基本使用方法

    头记:vim作为被大多数程序员所推崇的编辑器,是源于它的自由灵活以及令人舒服的输入模式,但对于新手来说无疑是个噩梦(需要记太多的命令), 而作为使用了vim有一段时间的我来说,总结下常用的命令,以备新 ...

  10. 内容提供者 DocumentProvider Uri工具类

    Activity /**详见http://blog.csdn.net/coder_pig/article/details/47905881 Calendar Provider:日历提供者,就是针对针对 ...