POJ 3608 Bridge Across Islands [旋转卡壳]
| Time Limit: 1000MS | Memory Limit: 65536K | |||
| Total Submissions: 10455 | Accepted: 3093 | Special Judge | ||
Description
Thousands of thousands years ago there was a small kingdom located in the middle of the Pacific Ocean. The territory of the kingdom consists two separated islands. Due to the impact of the ocean current, the shapes of both the islands became convex polygons. The king of the kingdom wanted to establish a bridge to connect the two islands. To minimize the cost, the king asked you, the bishop, to find the minimal distance between the boundaries of the two islands.

Input
The input consists of several test cases.
Each test case begins with two integers N, M. (3 ≤ N, M ≤ 10000)
Each of the next N lines contains a pair of coordinates, which describes the position of a vertex in one convex polygon.
Each of the next M lines contains a pair of coordinates, which describes the position of a vertex in the other convex polygon.
A line with N = M = 0 indicates the end of input.
The coordinates are within the range [-10000, 10000].
Output
For each test case output the minimal distance. An error within 0.001 is acceptable.
Sample Input
4 4
0.00000 0.00000
0.00000 1.00000
1.00000 1.00000
1.00000 0.00000
2.00000 0.00000
2.00000 1.00000
3.00000 1.00000
3.00000 0.00000
0 0
Sample Output
1.00000
Source
题意:给出两个凸多边形,求他们之间的最近距离
经典:http://blog.csdn.net/acmaker/article/details/3178696
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
typedef long long ll;
const int N=5e4+;
const double INF=1e99;
const double eps=1e-; inline int sgn(double x){
if(abs(x)<eps) return ;
else return x<?-:;
} struct Vector{
double x,y;
Vector(double a=,double b=):x(a),y(b){}
bool operator <(const Vector &a)const{
return sgn(x-a.x)<||(sgn(x-a.x)==&&sgn(y-a.y)<);
}
};
typedef Vector Point;
Vector operator +(Vector a,Vector b){return Vector(a.x+b.x,a.y+b.y);}
Vector operator -(Vector a,Vector b){return Vector(a.x-b.x,a.y-b.y);}
Vector operator *(Vector a,double b){return Vector(a.x*b,a.y*b);}
Vector operator /(Vector a,double b){return Vector(a.x/b,a.y/b);}
bool operator ==(Vector a,Vector b){return sgn(a.x-b.x)==&&sgn(a.y-b.y)==;}
double Dot(Vector a,Vector b){return a.x*b.x+a.y*b.y;}
double Cross(Vector a,Vector b){return a.x*b.y-a.y*b.x;} double Len(Vector a){return sqrt(Dot(a,a));}
double Len2(Vector a){return Dot(a,a);}
double DisTL(Point p,Point a,Point b){
Vector v1=p-a,v2=b-a;
return abs(Cross(v1,v2)/Len(v2));
}
double DisTS(Point p,Point a,Point b){
if(a==b) return Len(p-a);
Vector v1=p-a,v2=p-b,v3=b-a;
if(sgn(Dot(v2,v3))>) return Len(v2);
else if(sgn(Dot(v1,v3))<) return Len(v1);
else return abs(Cross(v1,v3)/Len(v3));
} int n,m;
Point p[N],q[N];
double RotatingCalipers(Point p[],int n,Point q[],int m){
double ans=INF;
p[n+]=p[];
q[m+]=q[];
int j=,k=,t;
for(int i=;i<=n;i++) if(p[i].y<p[j].y) j=i;
for(int i=;i<=m;i++) if(q[i].y>q[k].y) k=i;
for(int i=;i<=n;i++){
while((t=sgn(Cross(p[j+]-p[j],q[k]-q[k+])))<) k=k%m+;
if(t==){
ans=min(ans,min(DisTS(q[k],p[j],p[j+]),DisTS(q[k+],p[j],p[j+])));
ans=min(ans,min(DisTS(p[j],q[k],q[k+]),DisTS(p[j+],q[k],q[k+])));
}else ans=min(ans,DisTS(q[k],p[j],p[j+]));
j=j%n+;
}
return ans;
} int main(int argc, const char * argv[]) {
while(true){
scanf("%d%d",&n,&m);if(n==&&m==) break;
for(int i=;i<=n;i++) scanf("%lf%lf",&p[i].x,&p[i].y);
for(int i=;i<=m;i++) scanf("%lf%lf",&q[i].x,&q[i].y);
double ans=min(RotatingCalipers(p,n,q,m),RotatingCalipers(q,m,p,n));
printf("%.5f\n",ans);
}
}
POJ 3608 Bridge Across Islands [旋转卡壳]的更多相关文章
- POJ 3608 Bridge Across Islands(旋转卡壳,两凸包最短距离)
Bridge Across Islands Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7202 Accepted: ...
- POJ 3608 Bridge Across Islands(计算几何の旋转卡壳)
Description Thousands of thousands years ago there was a small kingdom located in the middle of the ...
- POJ 3608 Bridge Across Islands (旋转卡壳)
[题目链接] http://poj.org/problem?id=3608 [题目大意] 求出两个凸包之间的最短距离 [题解] 我们先找到一个凸包的上顶点和一个凸包的下定点,以这两个点为起点向下一个点 ...
- POJ 3608 Bridge Across Islands --凸包间距离,旋转卡壳
题意: 给你两个凸包,求其最短距离. 解法: POJ 我真的是弄不懂了,也不说一声点就是按顺时针给出的,不用调整点顺序. 还是说数据水了,没出乱给点或给逆时针点的数据呢..我直接默认顺时针给的点居然A ...
- POJ - 3608 Bridge Across Islands【旋转卡壳】及一些有趣现象
给两个凸包,求这两个凸包间最短距离 旋转卡壳的基础题 因为是初学旋转卡壳,所以找了别人的代码进行观摩..然而发现很有意思的现象 比如说这个代码(只截取了关键部分) double solve(Point ...
- ●POJ 3608 Bridge Across Islands
题链: http://poj.org/problem?id=3608 题解: 计算几何,求两个凸包间的最小距离,旋转卡壳 两个凸包间的距离,无非下面三种情况: 所以可以基于旋转卡壳的思想,去求最小距离 ...
- poj 3608 Bridge Across Islands
题目:计算两个不相交凸多边形间的最小距离. 分析:计算几何.凸包.旋转卡壳.分别求出凸包,利用旋转卡壳求出对踵点对,枚举距离即可. 注意:1.利用向量法判断旋转,而不是计算角度:避免精度问题和TLE. ...
- poj 3608 Bridge Across Islands 两凸包间最近距离
/** 旋转卡壳,, **/ #include <iostream> #include <algorithm> #include <cmath> #include ...
- POJ 2187 Beauty Contest【旋转卡壳求凸包直径】
链接: http://poj.org/problem?id=2187 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...
随机推荐
- angular2 表单验证
模版式表单 (1) angular遇到form自动接管,不想自动接管,添加ngNoForm,当标签为div时,但想被表单接管,添加ngForm; (2) ngForm可以被模版本地变量引用,以便在模版 ...
- jq.paginator分页插件稍加修改
样式一: 样式二: 此分页功能在jq.paginator分页插件上稍加修改. 必加模板html: <div id="jqPaginator"> <div id=& ...
- 有用的linux命令笔记
date cal [month] [year] bc 计算器 mkdir -p /home/bird/ 连续建立文件夹 mkdir -m 711 test2 创建文件夹是的权限 mv -i 询问是非覆 ...
- PHP截取中英文字符串
//如果字符串长度超过10,则截取并以省略号结尾 function sub($str){ $str=(string)$str; if( mb_strlen($str,'utf-8') >10){ ...
- phpMyAdmin访问远程MySQL数据库的方法
本地phpmyadmin远程连接服务器端MySQL 首先要确定你的mysql远程连接已开启,如果没有开启按照下面的二个方法操作: 方法一:改表法 因为在linux环境下,默认是关闭3306端口远程连接 ...
- git只添加指定类型的文件的.gitignore规则
#忽略根目录下的所有文件 * #忽略子目录下的所有文件 /* #包含目录 !*/ #指定不忽略的文件 !*.c !*.h #忽略根目录下的文件 /build/ /appveyor/ /pear/ /s ...
- IOS中UIScrollView的contentSize、contentOffset和contentInset属性
IOS中,UIScrollView是可以滚动的视图,其中最常用的UITableView就是继承了UIScrollView. 跟所有的view一样,UIScrollView有一个frame属 性,同时, ...
- ASP.NET导出word实例
ASP.NET导出word实例 最近遇到一个题目就是如何在asp.net中将数据导出到word中,由于数据是动态的,所以需要在后台拼出想要的的格式,翻遍了网页找出了一个比较满意的代码,感谢那位高手.代 ...
- 关于手残,搞废我的OLED屏幕的 追悼会
2017-12-1913:36:41 昨天按照B站的资料利用esp12F做了一个天气站,可预报天气,惭愧的是模型做好了,照片还没拍就夭折了,可怜了我20块的屏幕,我心伤悲,莫知我哀呀! 本来调试已经成 ...
- node.js进阶话题
< h3>notes_控制流 //forloopi.js var fs = require('fs'); var files = ['a.txt', 'b.txt', 'c.txt']; ...