Bridge Across Islands POJ - 3608 旋转卡壳求凸包最近距离
\(\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 旋转卡壳求凸包最近距离的更多相关文章
- poj 3608 旋转卡壳求不相交凸包最近距离;
题目链接:http://poj.org/problem?id=3608 #include<cstdio> #include<cstring> #include<cmath ...
- poj 2187 Beauty Contest , 旋转卡壳求凸包的直径的平方
旋转卡壳求凸包的直径的平方 板子题 #include<cstdio> #include<vector> #include<cmath> #include<al ...
- UVa 1453 - Squares 旋转卡壳求凸包直径
旋转卡壳求凸包直径. 参考:http://www.cppblog.com/staryjy/archive/2010/09/25/101412.html #include <cstdio> ...
- POJ 2187 Beauty Contest【旋转卡壳求凸包直径】
链接: http://poj.org/problem?id=2187 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...
- bzoj1185 [HNOI2007]最小矩形覆盖 旋转卡壳求凸包
[HNOI2007]最小矩形覆盖 Time Limit: 10 Sec Memory Limit: 162 MBSec Special JudgeSubmit: 2081 Solved: 920 ...
- 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 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9768 Accepted: ...
- POJ 3608 旋转卡壳
思路: 旋转卡壳应用 注意点&边 边&边 点&点 三种情况 //By SiriusRen #include <cmath> #include <cstdi ...
- poj 2079(旋转卡壳求解凸包内最大三角形面积)
Triangle Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 9060 Accepted: 2698 Descript ...
随机推荐
- 升级 AngularJS 至 Angular
Victor Savkin 大神撰写了一系列文章详细介绍如何升级 AngularJS 应用: NgUpgrade in Depth Upgrade Shell Two Approaches to Up ...
- react-router4.x 组件和api介绍
react-router实用4.2.0 react-router非常复杂整体,比vue-router强大很多,好好研究,对你自身能力提高很有帮助 安装 cnpm install react-route ...
- ABP仓储
简介 我们都知道ABP已经实现了仓储模式,支持EF core 和dapper 进行数据库的连接和管理,可以很方便的注入仓储来操作你的数据,不需要自己单独定义一个仓储来实现,通用的仓储实现了通用的cru ...
- C#理解泛型(源代码)及 default(T)
1.类型不安全.且代码无法遍历重用的源代码. 2.泛型源代码 源代码下载: http://files.cnblogs.com/files/qqhfeng/ConsoleApplication1.rar
- DAY11-MYSQL索引原理与慢查询优化
一 介绍 为何要有索引? 一般的应用系统,读写比例在10:1左右,而且插入操作和一般的更新操作很少出现性能问题,在生产环境中,我们遇到最多的,也是最容易出问题的,还是一些复杂的查询操作,因此对查询语句 ...
- linux设置自动获取IP地址
右键单击,选择设置 勾选桥接模式
- jetty分析
jetty处理过程: 1 new Server() (1)初试化线程池 生成固定大小线程数,新来的线程放入BlockingQueue. (2)初始化ServerConnector 初始化 sche ...
- go语言linux下安装
1.从http://golang.org/dl/下载最新版本的GO语言二进制档案包. 注意:根据操作系统和计算架构正确选择档案包 2.使用tar命令将档案包解压到/usr/local目录中.具体方法如 ...
- php学习笔记-do while循环
do{ func(); }while(condition) do while执行逻辑是先执行循环体里面的代码,再判断condition是否为true,如果是则和while循环一样了.如果conditi ...
- python3-password在输入密码时隐藏密码
# Auther: Aaron Fan #这个脚本请在命令行去执行才可以试出效果,pycharm这里无法测试这个脚本,切记!import getpass _username = "Aaron ...