POJ 3525 Most Distant Point from the Sea (半平面交+二分)
|
Most Distant Point from the Sea
Description The main land of Japan called Honshu is an island surrounded by the sea. In such an island, it is natural to ask a question: “Where is the most distant point from the sea?” The answer to this question for Honshu was found in 1996. The most distant point is located in former Usuda Town, Nagano Prefecture, whose distance from the sea is 114.86 km. In this problem, you are asked to write a program which, given a map of an island, finds the most distant point from the sea in the island, and reports its distance from the sea. In order to simplify the problem, we only consider maps representable by convex polygons. Input The input consists of multiple datasets. Each dataset represents a map of an island, which is a convex polygon. The format of a dataset is as follows.
Every input item in a dataset is a non-negative integer. Two input items in a line are separated by a space. n in the first line is the number of vertices of the polygon, satisfying 3 ≤ n ≤ 100. Subsequent n lines are the x- and y-coordinates of the n vertices. Line segments (xi, yi)–(xi+1, yi+1) (1 ≤ i ≤ n − 1) and the line segment (xn, yn)–(x1, y1) form the border of the polygon in counterclockwise order. That is, these line segments see the inside of the polygon in the left of their directions. All coordinate values are between 0 and 10000, inclusive. You can assume that the polygon is simple, that is, its border never crosses or touches itself. As stated above, the given polygon is always a convex one. The last dataset is followed by a line containing a single zero. Output For each dataset in the input, one line containing the distance of the most distant point from the sea should be output. An output line should not contain extra characters such as spaces. The answer should not have an error greater than 0.00001 (10−5). You may output any number of digits after the decimal point, provided that the above accuracy condition is satisfied. Sample Input 4 Sample Output 5000.000000 Source |
||||||||||||||||||||||
模板题,没啥说的
求在多边形内,到边的距离最大的点
枚举半径,用半平面交判断
/* ***********************************************
Author :kuangbin
Created Time :2013/8/18 15:11:26
File Name :F:\2013ACM练习\专题学习\计算几何\半平面交\POJ3525.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 PI = acos(-1.0);
int sgn(double x)
{
if(fabs(x) < eps) return ;
if(x < ) return -;
else return ;
}
struct Point
{
double x,y;
Point(){}
Point(double _x,double _y)
{
x = _x; y = _y;
}
Point operator -(const Point &b)const
{
return Point(x - b.x, y - b.y);
}
double operator ^(const Point &b)const
{
return x*b.y - y*b.x;
}
double operator *(const Point &b)const
{
return x*b.x + y*b.y;
}
};
struct Line
{
Point s,e;
double k;
Line(){}
Line(Point _s,Point _e)
{
s = _s; e = _e;
k = atan2(e.y - s.y,e.x - s.x);
}
Point operator &(const Line &b)const
{
Point res = s;
double t = ((s - b.s)^(b.s - b.e))/((s - e)^(b.s - b.e));
res.x += (e.x - s.x)*t;
res.y += (e.y - s.y)*t;
return res;
}
};
//半平面交,直线的左边代表有效区域
bool HPIcmp(Line a,Line b)
{
if(fabs(a.k - b.k) > eps)return a.k < b.k;
return ((a.s - b.s)^(b.e - b.s)) < ;
}
Line Q[];
void HPI(Line line[], int n, Point res[], int &resn)
{
int tot = n;
sort(line,line+n,HPIcmp);
tot = ;
for(int i = ;i < n;i++)
if(fabs(line[i].k - line[i-].k) > eps)
line[tot++] = line[i];
int head = , tail = ;
Q[] = line[];
Q[] = line[];
resn = ;
for(int i = ; i < tot; i++)
{
if(fabs((Q[tail].e-Q[tail].s)^(Q[tail-].e-Q[tail-].s)) < eps || fabs((Q[head].e-Q[head].s)^(Q[head+].e-Q[head+].s)) < eps)
return;
while(head < tail && (((Q[tail]&Q[tail-]) - line[i].s)^(line[i].e-line[i].s)) > eps)
tail--;
while(head < tail && (((Q[head]&Q[head+]) - line[i].s)^(line[i].e-line[i].s)) > eps)
head++;
Q[++tail] = line[i];
}
while(head < tail && (((Q[tail]&Q[tail-]) - Q[head].s)^(Q[head].e-Q[head].s)) > eps)
tail--;
while(head < tail && (((Q[head]&Q[head-]) - Q[tail].s)^(Q[tail].e-Q[tail].e)) > eps)
head++;
if(tail <= head + )return;
for(int i = head; i < tail; i++)
res[resn++] = Q[i]&Q[i+];
if(head < tail - )
res[resn++] = Q[head]&Q[tail];
}
Point p[];
Line line[];
//*两点间距离
double dist(Point a,Point b)
{
return sqrt((a-b)*(a-b));
}
void change(Point a,Point b,Point &c,Point &d,double p)//将线段ab往左移动距离p
{
double len = dist(a,b);
double dx = (a.y - b.y)*p/len;
double dy = (b.x - a.x)*p/len;
c.x = a.x + dx; c.y = a.y + dy;
d.x = b.x + dx; d.y = b.y + dy;
}
Point pp[];
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int n;
while(scanf("%d",&n) == && n)
{
for(int i = ;i < n;i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
double l = , r = ;
double ans = ;
while(r - l >= eps)
{
double mid = (l+r)/;
for(int i = ;i < n;i++)
{
Point t1,t2;
change(p[i],p[(i+)%n],t1,t2,mid);
line[i] = Line(t1,t2);
}
int resn;
HPI(line,n,pp,resn);
if(resn == )
r = mid - eps;
else
{
ans = mid;
l = mid + eps;
}
}
printf("%.6f\n",ans);
}
return ;
}
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 (半平面交)
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
http://poj.org/problem?id=3525 给出一个凸包,要求凸包内距离所有边的长度的最小值最大的是哪个 思路:二分答案,然后把凸包上的边移动这个距离,做半平面交看是否有解. #in ...
- LA 3890 Most Distant Point from the Sea(半平面交)
Most Distant Point from the Sea [题目链接]Most Distant Point from the Sea [题目类型]半平面交 &题解: 蓝书279 二分答案 ...
- POJ 3525 Most Distant Point from the Sea (半平面交向内推进+二分半径)
题目链接 题意 : 给你一个多边形,问你里边能够盛的下的最大的圆的半径是多少. 思路 :先二分半径r,半平面交向内推进r.模板题 #include <stdio.h> #include & ...
- POJ 3525 Most Distant Point from the Sea 二分+半平面交
题目就是求多变形内部一点. 使得到任意边距离中的最小值最大. 那么我们想一下,可以发现其实求是看一个圆是否能放进这个多边形中. 那么我们就二分这个半径r,然后将多边形的每条边都往内退r距离. 求半平面 ...
- POJ3525 Most Distant Point from the Sea(半平面交)
给你一个凸多边形,问在里面距离凸边形最远的点. 方法就是二分这个距离,然后将对应的半平面沿着法向平移这个距离,然后判断是否交集为空,为空说明这个距离太大了,否则太小了,二分即可. #pragma wa ...
- 简单几何(半平面交+二分) LA 3890 Most Distant Point from the Sea
题目传送门 题意:凸多边形的小岛在海里,问岛上的点到海最远的距离. 分析:训练指南P279,二分答案,然后整个多边形往内部收缩,如果半平面交非空,那么这些点构成半平面,存在满足的点. /******* ...
- POJ 3525 半平面交+二分
二分所能形成圆的最大距离,然后将每一条边都向内推进这个距离,最后所有边组合在一起判断时候存在内部点 #include <cstdio> #include <cstring> # ...
随机推荐
- NOIP模拟赛 城市
题目描述 $ZZQ$ 是一国之主. 这个国家有$N$个城市, 第$i$个城市与第$(i + 1) (mod N)$和$(i - 1) (mod N)$在一个正$N$边形相连. $ZZQ$ 又新建了$N ...
- VI编辑,配置文件
1,VI编辑 vi 分为3种模式 1>一般模式: [Ctrl + f ] 下一页 [Ctrl + b ] 上一页 [n+ enter] 向下移动n行 eg:2 ...
- python之smtplib库学习
# -*- coding:utf-8 -*- import smtplibfrom email.mime.text import MIMETextfrom email import encodersf ...
- GitBash、EGit、SourceTree三个Git管理工具对比
Git管理工具对比(GitBash.EGit.SourceTree) GitBash是采用命令行的方式对版本进行管理,功能最为灵活强大,但是由于需要手动输入希望修改的文件名,所以相对繁琐. EGit是 ...
- PHP发送邮件:如何自定义reply-to头部以及附件
虽然有现成的类库(如PEAR)可以很方便地实现附件添加和发送,但是对于一些小站点(服务器硬件.网站规模都不理想),安装PEAR可能会带来不必要的负担,降低WEB程序运行效率. 通过对邮件格式的认识,我 ...
- nginx 服务器篇
Nginx 服务器类型 1. Web服务器 Web服务器用于提供HTTP(包括HTTPS)的访问,例如Nginx.Apache.IIS等. 2. 应用程序服务器 应用程序服务器能够用于应用程序的运行, ...
- Effective C++笔记(二):构造/析构/赋值运算
参考:http://www.cnblogs.com/ronny/p/3740926.html 条款05:了解C++默默编写并调用哪些函数 如果自定义一个空类的话,会自动生成默认构造函数.拷贝构造函数. ...
- GDB调试实用命令
个人感觉从windows平台转到linux平台一个不适应的地方就是调试器的使用.因为windows下调试器基本上都依赖快捷键和图像界面来完成操作,就算是windbg这种伪命令行的工具,命令也很简单比较 ...
- python开发学习-day10(select/poll/epoll回顾、redis、rabbitmq-pika)
s12-20160319-day10 *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: ...
- 【LOJ】#2007. 「SCOI2015」国旗计划
题解 考虑朴素的做法,断环为链,复制2M个,找到一个位置i,f(i)是这个位置之前开始的线段,结束位置最远的位置在哪 然后对于每一个人,从自己线段的起点往下跳,跳到起点+M或以后的步数就是答案 我们发 ...