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. 【转】android使用File Explorer无法访问系统内部文件--不错

    原文网址:http://blog.csdn.net/yangqicong11/article/details/8747042 设备:Samsung GT-P3110 系统:Android 4.1.1 ...

  2. 深入 JavaScript(6) - 一静一动

    这里是JavaScript核心的内容了. 挺多的JavaScript测试题也是围绕这个出的. 这里的一静一动指的是: 静, 词法作用域 - Lexical scoping 动, 动态绑定this的值 ...

  3. Linux之V4L2视频采集编程详解

     V4L2(Video For Linux Two) 是内核提供给应用程序访问音.视频驱动的统一接口. Linux系统中,视频设备被当作一个设备文件来看待,设备文件存放在 /dev目录下,完整路径的设 ...

  4. markdown转dokuwiki

    markdown markdown格式变得越来越通用,很多博客,云笔记,github等等都支持markdown编写,markdown也能很方便的转化为pdf,html等格式.公司的文档用的dokuwi ...

  5. Fancybox——学习(1)

    转载:http://www.helloweba.com/view-blog-65.html Fancybox是一款优秀的jquery插件,它能够展示丰富的弹出层效果.前面我们有文章介绍了facybox ...

  6. android中定位光标位置

    edittext.setSelection(int); edittext.setText(123);//设置edittext中的内容 edittext.setSelection(123.length( ...

  7. Android应用程序的安装位置

    Android应用程序的默认安装位置以及是否可移动取决于开发者在其AndroidManifest.xml中的设置:   <manifestxmlns:android="http://s ...

  8. jsPlumb开发入门教程(实现html5拖拽连线)

    jsPlumb是一个强大的JavaScript连线库,它可以将html中的元素用箭头.曲线.直线等连接起来,适用于开发Web上的图表.建模工具等.它同时支持jQuery+jQuery UI.MooTo ...

  9. Nginx的安装及简单配置

    Nginx安装 1.下载相关组件 yum install -y gcc gcc-c++                                   #安装C/C++编译器 yum -y ins ...

  10. 网页CSS2

    列表与方块 width , hight (top, bottom ,left , right)   只有在决对坐标下才起作用 下面的使用与 ol  ul list-style:none // 取消序号 ...