POJ 3525 Most Distant Point from the Sea
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的更多相关文章
- POJ 3525 Most Distant Point from the Sea [半平面交 二分]
Most Distant Point from the Sea Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 5153 ...
- POJ 3525 Most Distant Point from the Sea (半平面交+二分)
Most Distant Point from the Sea Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 3476 ...
- 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 ...
- POJ 3525 Most Distant Point from the Sea (半平面交向内推进+二分半径)
题目链接 题意 : 给你一个多边形,问你里边能够盛的下的最大的圆的半径是多少. 思路 :先二分半径r,半平面交向内推进r.模板题 #include <stdio.h> #include & ...
- POJ 3525 Most Distant Point from the Sea 二分+半平面交
题目就是求多变形内部一点. 使得到任意边距离中的最小值最大. 那么我们想一下,可以发现其实求是看一个圆是否能放进这个多边形中. 那么我们就二分这个半径r,然后将多边形的每条边都往内退r距离. 求半平面 ...
- 【POJ】【3525】Most Distant Point from the Sea
二分+计算几何/半平面交 半平面交的学习戳这里:http://blog.csdn.net/accry/article/details/6070621 然而这题是要二分长度r……用每条直线的距离为r的平 ...
- 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 ...
- poj 3525 凸多边形多大内切圆
Most Distant Point from the Sea Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 4758 ...
- LA 3890 Most Distant Point from the Sea(半平面交)
Most Distant Point from the Sea [题目链接]Most Distant Point from the Sea [题目类型]半平面交 &题解: 蓝书279 二分答案 ...
随机推荐
- 牛逼的 弹出层 layer !!!
功能强大,实用,操作方便,文档齐全. http://layer.layui.com/api.html 常用功能代码: <!doctype html> <html> <he ...
- Qt入门(3)——信号和槽
信号和槽用于对象间的通讯.信号/槽机制是Qt的一个中心特征并且也许是Qt与其它工具包的最不相同的部分.在图形用户界面编程中,我们经常希望一个窗口部件的一个变化被通知给另一个窗口部件.更一般地,我们希望 ...
- Activity — 4 launch mode
launchMode在多个Activity跳转的过程中扮演着重要的角色,它可以决定是否生成新的Activity实例,是否重用已存在的Activity实例,是否和其他Activity实例公用一个task ...
- hdu-1800
思路: 这题被坑的不轻. 首先花了一段时间想明白了思路是要找出现次数最多数字,以为这题就这样解决了,结果发现每个数字的最大长度是30,long long都装不下,因此就要用字符串来保存处理.然后在in ...
- Engineer Economic
1.选择题 10.下列哪项不属于总成本费用() A.生产成本 B.机会成本 C.管理费用 D.财务费用 第1章 11.下列哪项关于自有资金的表述是错误的(D) A.自有资金包括资本金 ...
- jQuery 左侧滑动
$("#slideleft button").click(function(){ var $lefty = $(this).next(); $lefty.animate({ lef ...
- Javascript:阻止浏览器默认右键事件,并显示定制内容
在逛一些知名图片社区的时候,遇到自己心怡的图片,想要右键另存的时候,默认的浏览器菜单不见了,却出现了如:[©kevin版权所有]之类的信息: 今天在看Javascript事件默认行为相关的知识,所以, ...
- 轻量级mvvm Web开发框架 postby:http://zhutty.cnblogs.com
今天特别郁闷,怎么说呢,之前一直就用angular,然后这两天用的是avalon这东西,反正,一开始没时间去玩它,第一个任务就是封装个jq插件,实现一个小功能.反正呢,就是越写越郁闷.用过angula ...
- windows服务程序
首先创建一个myService的窗体程序作为服务安装卸载控制器(管理员身份运行vs,windows服务的安装卸载需要管理员权限) 在同一个解决方案里面添加一个windows服务程序,取名myWin ...
- EditText设置可以编辑和不可编辑状态
1.首先想到在xml中设置android:editable="false",但是如果想在代码中动态设置可编辑状态,没有找到对应的函数 2.然后尝试使用editText.setFoc ...