\(\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. Oracle 数据库表(常见的表)

    数据库表(常见的表) 堆组织表:普通表 索引组织表:iot 嵌套表 临时表 外部表 1 表 一个表最多1000列,oracle会把列大于254的行存储在多个单独的行段中, 表中的行是无限的,    术 ...

  2. Bresenham快速画直线算法

    现在的计算机的图像的都是用像素表示的,无论是点.直线.圆或其他图形最终都会以点的形式显示.人们看到屏幕的直线只不过是模拟出来的,人眼不能分辨出来而已.那么计算机是如何画直线的呢,其实有比较多的算法,这 ...

  3. rails表单控件helper

    1.form加入HTML属性 <%= form_for(@device, :html => {:method=>"post", :id=>"for ...

  4. showModalDialog()子窗口刷新父窗口

    今天再次使用showModalDialog(),发现了两个问题,一是子窗口如何刷新父窗口,二是窗口的参数问题. 1 子窗口刷新父窗口 如果是window.open();问题就好办,直接用window. ...

  5. 第五章 深入class文件结构(待续)

    JVM指令集简介 class文件头的表示形式 常量池 类信息 Fields和Methods定义 类属性描述 Javap生成的class文件结构

  6. 问题:sqlserver有没有类似Oracle的LISTAGG;结果: 灵活运用 SQL SERVER FOR XML PATH

    灵活运用 SQL SERVER FOR XML PATH FOR XML PATH 有的人可能知道有的人可能不知道,其实它就是将查询结果集以XML形式展现,有了它我们可以简化我们的查询语句实现一些以前 ...

  7. 多媒体基础知识之YUV数据

    1.什么是YUV格式 YUV,是一种颜色编码方法.Y表示明亮度(Luminance.Luma),也就是灰度值.U和V则是色度.浓度(Chrominance.Chroma),作用是描述影像色彩及饱和度, ...

  8. DAY12-前端之HTML

    一.html初识 web服务本质 import socket def main(): sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) ...

  9. JavaScript中常用的函数

    javascript函数一共可分为五类:  ·常规函数  ·数组函数  ·日期函数  ·数学函数  ·字符串函数 1.常规函数  javascript常规函数包括以下9个函数:  (1)alert函数 ...

  10. 卸载phonegap

    npm uninstall cordova  -gnpm uninstall phonegap -g