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菜单详解——理解android中的Menu--不错

    原文网址:http://www.cnblogs.com/qingblog/archive/2012/06/08/2541709.html 前言 今天看了pro android 3中menu这一章,对A ...

  2. 【转】用串口登录Beaglebone Black、用usb共享电脑网络、内核模块的本地编译

    原文网址:http://bbs.eeworld.com.cn/thread-431507-1-1.html 串口连接BBB使用usb线可以连接BBB和电脑,用ssh就可以登录BBB来进行操作.但有时候 ...

  3. mongodb sort limit和skip用法

    > db.mediaCollection.find().skip().toArray() [ { "_id" : ObjectId("5353463193efef0 ...

  4. 【7】JAVA---地址App小软件(AddrBusiness.class)(逻辑层)

    这个...没多少好解释的... 表现层的增删改查的具体实现类. package cn.hncu.addr.business; import javax.swing.JOptionPane; impor ...

  5. 关于我的FGC的OAuth2.0认证。

    这个名字估计很冷门,估计不会有人看到吧,我猜测的. (阅读以下全文之前请先搞定翻^#$%@#墙这件事.昨天看了一个笑话说墙之父方校长说自己有六个VPN账号,只是为了测试自己的墙好用还是VPN好用.哈哈 ...

  6. word-wrap: break-word 和 word-break: break-all 到底有啥区别?

    做项目改bug的时候,遇到过好多次,要么是文本超出文本区域,或者单词太长(一般是url链接中的一些鬼),把装它的标签强制撑大,导致一些响应式问题.除此之外,还有很多问题,每次都是恍然醒悟,然后又在网上 ...

  7. servletContext百科

    servletContext 编辑   servletContext接口是Servlet中最大的一个接口,呈现了web应用的Servlet视图.ServletContext实例是通过 getServl ...

  8. docker iptables 端口映射 nat

    docker  iptables  端口映射  nat #!/bin/bash pro='tcp' NAT_Host='Host_A' NAT_Port=8080 Dst_Host='Host_B' ...

  9. 网页HTML1

    表格表单 表格, <tabale>    -------表格 <tr>            --------------行 <td>             -- ...

  10. SQL从入门到基础–08 Union、Union all及案例

    一.联合结果集 1. 简单的结果集联合: Select FNumber,FName,FAge from T_Employee union select FidCardNumber,FName,FAge ...