\(\color{#0066ff}{题目描述}\)

几千年前,有一个小王国位于太平洋的中部。王国的领土由两个分离的岛屿组成。由于洋流的冲击,两个岛屿的形状都变成了凸多边形。王国的国王想建立一座桥来连接这两个岛屿。为了把成本降到最低,国王要求你,主教,找到两个岛屿边界之间最小的距离。

\(\color{#0066ff}{输入格式}\)

输入由几个测试用例组成。

每个测试用两个整数n,m(3≤n,m≤10000)开始

接下来的n行中的每一行都包含一对坐标,用来描述顶点在一个凸多边形中的位置。

下一条m线中的每一条都包含一对坐标,它描述了一个顶点在另一个凸多边形中的位置。

n=m=0的行表示输入的结束。

坐标在这个范围内[-10000,10000]。

\(\color{#0066ff}{输出格式}\)

对每个测试用例输出最小距离。在0.001范围内的错误是可以接受的

\(\color{#0066ff}{输入样例}\)

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

\(\color{#0066ff}{输出样例}\)

1.00000

\(\color{#0066ff}{数据范围与提示}\)

none

\(\color{#0066ff}{题解}\)

旋转卡壳

输入的时候就是凸包,所以不用再求了

对于最近距离,可能是点点,点边, 边边,这个可以在点到边的距离那里一并处理

距离可以通过面积判断(底固定,高最大)

(叉积是负的,所以用<) 找到高最小的更新ans

#include <cstdio>
#include <cmath>
#include <cctype>
#include <algorithm>
#define _ 0
#define LL long long
inline LL in() {
LL x = 0, f = 1; char ch;
while(!isdigit(ch = getchar()))(ch == '-') && (f = -f);
while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar();
return x * f;
}
const int maxn = 1e4 + 100;
int n, m;
struct node {
double x, y;
node(double x = 0, double y = 0)
:x(x), y(y) {}
node operator - (const node &b) const {
return node(x - b.x, y - b.y);
}
double operator ^ (const node &b) const {
return x * b.y - y * b.x;
}
double operator * (const node &b) const {
return x * b.x + y * b.y;
}
double dis() {
return sqrt(x * x + y * y);
}
double dis(const node &a, const node &b) {
node c = *this;
//垂足不在线段ab上
if((b - a) * (c - a) < 0) return (c - a).dis();
if((a - b) * (c - b) < 0) return (c - b).dis();
//平行四边形面积 / 底 = 高
return fabs(((a - b) ^ (c - b)) / (a - b).dis());
}
}A[maxn], B[maxn];
double Min(node a, node b, node c, node d) {
return std::min(std::min(c.dis(a,b),d.dis(a,b)),std::min(a.dis(c,d),b.dis(c,d)));
}
double work() {
double ans = 1e20;
int min = 0, max = 0;
for(int i = 0; i < n; i++) if(A[i].y < A[min].y) min = i;
for(int i = 0; i < m; i++) if(B[i].y > B[max].y) max = i;
A[n] = A[0], B[m] = B[0];
for(int i = 0; i < n; i++) {
node t = A[min + 1] - A[min];
while((t ^ (B[max] - A[min])) < (t ^ (B[max + 1] - A[min]))) max = (max + 1) % m;
ans = std::min(ans, Min(A[min], A[min + 1], B[max], B[max + 1]));
min = (min + 1) % n;
}
return ans;
}
int main() {
while("fuck") {
n = in(), m = in();
if(!n && !m) break;
for(int i = 0; i < n; i++) scanf("%lf%lf", &A[i].x, &A[i].y);
for(int i = 0; i < m; i++) scanf("%lf%lf", &B[i].x, &B[i].y);
printf("%.3f\n", work());
}
return 0;
}

Bridge Across Islands POJ - 3608 旋转卡壳求凸包最近距离的更多相关文章

  1. poj 3608 旋转卡壳求不相交凸包最近距离;

    题目链接:http://poj.org/problem?id=3608 #include<cstdio> #include<cstring> #include<cmath ...

  2. poj 2187 Beauty Contest , 旋转卡壳求凸包的直径的平方

    旋转卡壳求凸包的直径的平方 板子题 #include<cstdio> #include<vector> #include<cmath> #include<al ...

  3. UVa 1453 - Squares 旋转卡壳求凸包直径

    旋转卡壳求凸包直径. 参考:http://www.cppblog.com/staryjy/archive/2010/09/25/101412.html #include <cstdio> ...

  4. POJ 2187 Beauty Contest【旋转卡壳求凸包直径】

    链接: http://poj.org/problem?id=2187 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...

  5. bzoj1185 [HNOI2007]最小矩形覆盖 旋转卡壳求凸包

    [HNOI2007]最小矩形覆盖 Time Limit: 10 Sec  Memory Limit: 162 MBSec  Special JudgeSubmit: 2081  Solved: 920 ...

  6. POJ 3608 Bridge Across Islands(计算几何の旋转卡壳)

    Description Thousands of thousands years ago there was a small kingdom located in the middle of the ...

  7. poj 3608(旋转卡壳求解两凸包之间的最短距离)

    Bridge Across Islands Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9768   Accepted: ...

  8. POJ 3608 旋转卡壳

    思路: 旋转卡壳应用 注意点&边  边&边  点&点 三种情况 //By SiriusRen #include <cmath> #include <cstdi ...

  9. poj 2079(旋转卡壳求解凸包内最大三角形面积)

    Triangle Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 9060   Accepted: 2698 Descript ...

随机推荐

  1. win10/server2019 系统安装 详解

    https://www.microsoft.com/zh-cn/software-download/windows10 https://go.microsoft.com/fwlink/?LinkId= ...

  2. [置顶] 从零制作文件系统到JZ2440,使其支持telnet , ftp 和tftp

    转自:http://mp.weixin.qq.com/s?__biz=MzAxNTAyOTczMw==&mid=2649328515&idx=1&sn=5849fba4b44e ...

  3. CreateWaitableTimer和SetWaitableTimer

    负值表示相对时间,正值表示绝对时间,定时器精度为100ns (1ns=1/10亿 s),所以 -50000000 代表5秒,详见MSDN. 程序一为自动重置(先等待5秒,然后每1秒输出一次): #in ...

  4. java连接字符串操作,可用来向sql传值

    private static String concat(String tag,String Time) { // TODO Auto-generated method stub // return ...

  5. 设置MySQL允许外网访问(转)

    设置MySQL允许外网访问   1.修改配置文件sudo vim /etc/mysql/my.cnf把bind-address参数的值改成你的内/外网IP或0.0.0.0,或者直接注释掉这行. 2.登 ...

  6. Easyui datebox单击文本框显示日期选择 eayui版本1.5.4.1

    Easyui默认是点击文本框后面的图标显示日期,体验很不好,所以我想单击文本框就显示日期选择框,网上很多版本是1.3,1.4的,于是自己就比葫芦画瓢改了一个1.5.4.1的版本. 我参考了网上这个帖子 ...

  7. FactoryMethodPattern(23种设计模式之一)

    设计模式六大原则(1):单一职责原则 设计模式六大原则(2):里氏替换原则 设计模式六大原则(3):依赖倒置原则 设计模式六大原则(4):接口隔离原则 设计模式六大原则(5):迪米特法则 设计模式六大 ...

  8. CF609E Minimum spanning tree for each edge

    原来觉得是一个LCT,感觉自己瞬间傻掉…… 考虑到先做一个最小生成树求出做最小生成树的代价$ans$,顺便标记一下树边和非树边,把边按照输入$id$排序回去之后扫,如果扫到一条树边,那么此时的答案就是 ...

  9. html 连接数据库

    http://blog.csdn.net/haxker/article/details/4214001 http://www.cnblogs.com/chuncn/archive/2010/11/22 ...

  10. Umbraco Form 中需要为一个Form的某个field设置特别的CSS样式

    在项目开发中,我有一个需求,需要建立一个页面,这个页面上有一个form, 这个form上有一个checkbox, 就是普通的接受terms & conditions, 类似下图 这个项目中的U ...