UVA 3890 Most Distant Point from the Sea(二分法+半平面交)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=11358
【思路】
二分法+半平面交
二分与海边的的距离,由法向量可以得到平移后的各边,半平面交在特定精度判断是否有交集。
【代码】
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std; const double eps = 1e-; struct Pt {
double x,y;
Pt(double x=,double y=):x(x),y(y) {}
};
typedef Pt vec;
struct Line {
Pt P; vec v;
double ang;
Line () {};
Line (Pt P,vec v):P(P),v(v) { ang=atan2(v.y , v.x); }
bool operator < (const Line& rhs) const{
return ang<rhs.ang;
}
}; vec operator - (Pt A,Pt B) { return vec(A.x-B.x,A.y-B.y); }
vec operator + (vec A,vec B) { return vec(A.x+B.x,A.y+B.y); }
vec operator * (vec A,double p) { return vec(A.x*p,A.y*p); }
double Dot(vec A,vec B) { return A.x*B.x+A.y*B.y; }
double cross(Pt A,Pt B) { return A.x*B.y-A.y*B.x; }
double Len(vec A) { return sqrt(Dot(A,A)); }
vec Normal(vec A) { double L=Len(A); return vec(-A.y/L,A.x/L); } bool onleft(Line L,Pt P) { return cross(L.v,P-L.P)>; } Pt LineIntersection(Line a,Line b) {
vec u=a.P-b.P;
double t=cross(b.v,u)/cross(a.v,b.v);
return a.P+a.v*t;
}
int HalfplaneIntersection(Line* L,int n,Pt* poly) {
sort(L,L+n);
int first,last;
Pt *p=new Pt[n];
Line *q=new Line[n];
q[first=last=]=L[];
for(int i=;i<n;i++) {
while(first<last && !onleft(L[i],p[last-])) last--;
while(first<last && !onleft(L[i],p[first])) first++;
q[++last]=L[i];
if(fabs(cross(q[last].v,q[last-].v))<eps) {
last--;
if(onleft(q[last],L[i].P)) q[last]=L[i];
}
if(first<last) p[last-]=LineIntersection(q[last-],q[last]);
}
while(first<last && !onleft(q[first],p[last-])) last--;
if(last-first<=) return ;
p[last]=LineIntersection(q[last],q[first]);
int m=;
for(int i=first;i<=last;i++) poly[m++]=p[i];
return m;
} const int N = +;
Pt p[N],poly[N];
Line L[N];
vec v[N] , v2[N];
int n; int main() {
while(scanf("%d",&n)== && n) {
int m,x,y;
for(int i=;i<n;i++) {
scanf("%d%d",&x,&y);
p[i]=Pt(x,y);
}
for(int i=;i<n;i++) {
v[i]=p[(i+)%n]-p[i];
v2[i]=Normal(v[i]);
}
double left= , right=;
while(right-left>eps) {
double mid=left+(right-left)/;
for(int i=;i<n;i++) L[i]=Line(p[i]+v2[i]*mid,v[i]);
m=HalfplaneIntersection(L,n,poly);
if(!m) right=mid; else left=mid;
}
printf("%.6lf\n",left);
}
return ;
}
UVA 3890 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: 3476 ...
- poj3525Most Distant Point from the Sea(半平面交)
链接 求凸多边形内一点距离边最远. 做法:二分+半平面交判定. 二分距离,每次让每条边向内推进d,用半平面交判定一下是否有核. 本想自己写一个向内推进..仔细一看发现自己的平面交模板上自带.. #in ...
- POJ 3525 Most Distant Point from the Sea (半平面交向内推进+二分半径)
题目链接 题意 : 给你一个多边形,问你里边能够盛的下的最大的圆的半径是多少. 思路 :先二分半径r,半平面交向内推进r.模板题 #include <stdio.h> #include & ...
- 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 ...
- LA 3890 Most Distant Point from the Sea(半平面交)
Most Distant Point from the Sea [题目链接]Most Distant Point from the Sea [题目类型]半平面交 &题解: 蓝书279 二分答案 ...
- 简单几何(半平面交+二分) LA 3890 Most Distant Point from the Sea
题目传送门 题意:凸多边形的小岛在海里,问岛上的点到海最远的距离. 分析:训练指南P279,二分答案,然后整个多边形往内部收缩,如果半平面交非空,那么这些点构成半平面,存在满足的点. /******* ...
- uvalive 3890 Most Distant Point from the Sea
题意:求一个凸多边形中一点到边的最大距离. 思路:转换成在多边形内部,到每边距离为d的直线所围成的内多边形是否存在.也就是,二分距离+半平面交. #include<cstdio> #inc ...
- uva 1396 - Most Distant Point from the Sea
半平面的交,二分的方法: #include<cstdio> #include<algorithm> #include<cmath> #define eps 1e-6 ...
- UVALive 3890 Most Distant Point from the Sea(凸包最大内接园)
一个n个点的凸多边形,求多边形中离多边形边界最远的距离.实际上就是求凸包最大内接圆的半径. 利用半平面交求解,每次二分枚举半径d,然后将凸包每条边所代表的半平面沿其垂直单位法向量平移d,看所有平移后的 ...
随机推荐
- Hdu 4514 湫湫系列故事——设计风景线
湫湫系列故事--设计风景线 Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Total ...
- Inline functions
Problems: (Page 372) There are two problems with the use of proprocessor macros in C++. The first is ...
- Scala - error: not found: value SortedMap
先 IMPORT!!!! scala> import scala.collection._import scala.collection._ scala> SortedMap(" ...
- Jquery环境搭建前言
- 基于jQuery的图片左右轮播,基本原理通用
毕竟新人,写点基础的小东西,希望能和大家沟通交流,提高自己的水平. 这个是应用较多的轮播部分,希望能和大家分享一下思路,拓宽视野. 话不多说,上内容. 我的思路很简单就是通过判断index值的大小变化 ...
- Android App资源的查找过程分析
Android资源管理框架实际就是由AssetManager和Resources两个类来实现的.其中,Resources类可以根据ID来查找资源,而AssetManager类根据文件名来查找资源.事实 ...
- Toy Storage
Toy Storage 题型与2318 TOYS一样,注意要对线段排序,现在模板又更新了~~ #include<iostream> #include<cstdio> #incl ...
- POJ 2886 Who Gets the Most Candies? 线段树
题目: http://poj.org/problem?id=2886 左右转的果断晕,题目不难,关键是准确的转啊转.因为题目要求输出约数个数最多的数,所以预处理[1,500000]的约数的个数就行了. ...
- Java入门-浅析Java学习从入门到精通【转】
一. JDK (Java Development Kit) JDK是整个Java的核心,包括了Java运行环境(Java Runtime Envirnment),一堆Java工具和Java基础的类库 ...
- 第 3 章 单例模式【Singleton Pattern】
以下内容出自:24种设计模式介绍与6大设计原则 这个模式是很有意思,而且比较简单,但是我还是要说因为它使用的是如此的广泛,如此的有人缘,单例就是单一.独苗的意思,那什么是独一份呢?你的思维是独一份,除 ...