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,看所有平移后的 ...
随机推荐
- (转)IOS内存管理 retain release
obj-c本质就是"改进过的c语言",大家都知道c语言是没有垃圾回收(GC)机制的(注:虽然obj-c2.0后来增加了GC功能,但是在iphone上不能用,因此对于iOS平台的程序 ...
- IIS原理学习
IIS 原理学习 首先声明以下内容是我在网上搜索后整理的,在此只是进行记录,以备往后查阅只用. IIS 5.x介绍 IIS 5.x一个显著的特征就是Web Server和真正的ASP.NET Appl ...
- MySQL的多实例
一.准备工作 1.关闭mysql进程 # pkill # service mysqld stop 2.从系统服务中删除mysqld # chkconfi ...
- Linux运维工程师面试
一.Linux操作系统知识 1.常见的Linux发行版本都有什么?你最擅长哪一个?它的官网网站是什么?说明你擅长哪一块? 2.Linux开机启动流程详细步骤是什么?系统安装完,忘记密码如何破解? ...
- jdk环境变量配置(总结)
进行java开发,首先要安装jdk,安装了jdk后还要进行环境变量配置: 1.下载jdk(http://java.sun.com/javase/downloads/index.jsp),我下载的版本是 ...
- nginx Engine X静态网页服务器介绍
Nginx ("engine x") 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器. 反向代理(Reverse Proxy)方 ...
- PHP分页初探 一个最简单的PHP分页代码实现
PHP分页代码在各种程序开发中都是必须要用到的,在网站开发中更是必选的一项. 要想写出分页代码,首先你要理解SQL查询语句:select * from goods limit 2,7.PHP分页代码核 ...
- CentOS6.4 使用谷歌Chromium浏览器
那么,如果希望在CentOS/RHEL 7出来之前继续使用Chrome怎么办?使用Chrome的开源版本:Chromium. 1.切换到root: su - 或者 sudo -i 2.下载新的软件源定 ...
- corosync+pacemaker and drbd实现mysql高可用集群
DRBD:Distributed Replicated Block Device 分布式复制块设备,原理图如下 DRBD 有主双架构和双主架构的,当处于主从架构时,这个设备一定只有一个节点是可以读写的 ...
- wampserver修改默认根目录
1.打开wamp/scripts/config.inc.php ,修改$wwwDir = $c_installDir.’/www’; 2.打开wamp/bin/apache/apache2.4.9/c ...