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,看所有平移后的 ...
随机推荐
- Codevs 3287 货车运输 2013年NOIP全国联赛提高组(带权LCA+并查集+最大生成树)
3287 货车运输 2013年NOIP全国联赛提高组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 传送门 题目描述 Description A 国有 n 座 ...
- devenv compile errors collection
任务:使用 devenv commnd line 编译 VS 2010 工程. 使用 devenv 编译工程,要保证工程所需的 VC++目录 (VC++ Directories) 设置正确才能编译成功 ...
- centOS 多网卡 启动网络 eth0 does not to be present
centOS 6.4 中 em1 就是eth0... ---------------------------------------- http://www.php-oa.com/2012/03/07 ...
- Python3 字符编码
编码 字符串是一种数据类型,但是,字符串比较特殊的是还有一个编码问题. 因为计算机只能处理数字,如果要处理文本,就必须先把文本转换为数字才能处理.最早的计算机在设计时采用8个比特(bit)作为一个字节 ...
- jQuery选择器(一)
1.#id根据给定的ID匹配一个元素. <div id="notMe"><p>id="notMe"</p></div& ...
- How to say all the keyboard symbols in English and Chinese
How to say all the keyboard symbols in English Symbol English 中文 ~ tilde 波浪号 ` grave accent, backquo ...
- PHP学习笔记(2) - 对PHP的印象
一.PHP是一种简单易学的面向过程的弱类型动态脚本语言,本为制作简单的个人网站而开发,现如今经过多个版本的衍变甚至加入了一些面向对象的特性.PHP试图通过发展打进企业级开发,同时也使得它自身也越来越复 ...
- 第一个CUDA程序
开始学CUDA 先写一个简单的 #include<iostream>__global__ void add( int a, int b, int *c ) { *c = a + b;}in ...
- App评分
//应用实现评论跳转的两种方法: //第一种: //在iOS6.0前跳转到AppStore评分一般是直接跳转到AppStore评分 //NSString *evaluateString = [NSSt ...
- 数据库水平拆分和垂直拆分区别(以mysql为例)
数据库水平拆分和垂直拆分区别(以mysql为例) 数据库水平拆分和垂直拆分区别(以mysql为例) 案例: 简单购物系统暂设涉及如下表: 1.产品表(数据量10w,稳定) 2.订单表(数据 ...