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 ...
随机推荐
- git学习5 ecipse集成git(转载)
原文地址:http://blog.csdn.net/hhhccckkk/article/details/10458159 有的eclipse已经自带了GIt了,就不用安装了 1: 进行安装Git,和安 ...
- RabbitMQ 消息队列 安装及使用
RabbitMQ 消息队列安装: linux版本:CentOS 7 安装第一步:先关闭防火墙 1.Centos7.x关闭防火墙 [root@rabbitmq /]# systemctl stop fi ...
- appium_python 实现手势密码
直接上代码吧: from appium.webdriver.common.touch_action import TouchAction from driver import AppiumTest # ...
- 问题:C#根据生日计算属相;结果:C#实现根据年份计算生肖属相的方法
这篇文章主要介绍了C#实现根据年份计算生肖属相的方法,涉及C#数组与字符串的操作技巧,具有一定参考借鉴价值,需要的朋友可以参考下 本文实例讲述了C#实现根据年份计算生肖属相的方法.分享给大家供大家 ...
- 监控和安全运维 1.5 nagios监控客户端-1
3. Nagios安装 - 客户端(192.168.0.12)在客户端机器上 rpm -ivh http://www.aminglinux.com/bbs/data/attachment/forum/ ...
- WPF TextBox 一些设置技巧
WPF TextBox 一些设置技巧 运行环境:Win10 x64, NetFrameWork 4.8, 作者:乌龙哈里,日期:2019-05-01 参考: 章节: 取消输入法 输入方式设定为Over ...
- HTML以及DOM选择属性
http://www.cnblogs.com/season-huang/p/3360869.html
- UML在实践中的现状和一些建议
本文是我在csdn上看到的文章,由于认识中的共鸣,摘抄至此. 原文地址:http://blog.csdn.net/vrman/article/details/280157 UML在国内不少地方获得了应 ...
- repeater的command事件用法
当Repeater里面循环控件时就会用到command, 是Repeater控件的原生事件用法 Repeater里面如果循环控件,控件的ID是会被改变的 repeater.itemcommand+= ...
- git在eclipse中的配置 完整版 转载
http://www.cnblogs.com/zhxiaomiao/archive/2013/05/16/3081148.html