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> # ...
随机推荐
- Python语言库pyttsx3
这是一个文字转语音的python模块. 1. macos下安装的时候出现问题: 后来发现,Foundation, AppKit, PyObjCTools都不存在,主要原因是缺少依赖模块pyobjc, ...
- Linux文件访问流程及磁盘inode和block总结
Linux文件访问流程 inode是文件的唯一标识,文件名和inode的对应关系存放在上一级目录的block中:inode里有指向文件block的指针和文件的属性,从而通过block获得文件数据. 磁 ...
- IDEA配置toString方法
1.toString JSON带父类toString public java.lang.String toString() { final java.lang.StringBuilder sb = n ...
- plt-3D打印1
plt-3D打印 import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D ...
- 如何提交代码到CEPH Repo。 顺便庆祝下,提交了第一个ceph pull request。实现了从0到1的突破
庆祝一下!经过社区老司机的带路,昨天提交了第一个ceph pull request.实现了从0到1的突破,希望再接再厉提交更多代码到社区,为社区发展贡献一点自己力量. 提交的第一个被社区fix的bug ...
- PyCharm中 ImportError: No module named tensorflow
安装完 tensorflow 后在 PyCharm 中导入时显示找不到,可设置如下: PyCharm 中依次打开 File -> Settings -> Project:PycharmPr ...
- 字典dict常用方法
字典是列表中常用的方法,我们经常处理字典,字典嵌套,很多复杂的操作都来自于基础,只是改变了样式而已,本质是不变的.下面来看看字典中常用的功能都有那些: 1.clear(self) def cl ...
- persistencejs:异步javascript数据库映射库
persistence.js 是一个异步的 JavaScript 对象数据库映射(ORM)框架.拥有数据库无关的独立抽象层,可轻松支持新的数据库.该软件最开始是为浏览器设计的,利用 HTML5 的 W ...
- Android Service AIDL
http://blog.csdn.net/liuhe688/article/details/6400385 在Android中,如果我们需要在不同进程间实现通信,就需要用到AIDL技术去完成. AID ...
- Java switch case和数组
Java switch case 语句 switch case 语句判断一个变量与一系列值中某个值是否相等,每个值称为一个分支. 语法 switch case 语句格式: switch(express ...