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 ...
随机推荐
- IDEA编译器如何去掉注释中参数错误的提示
在使用idea的导入别人的项目的时候经常会在方法注释中出现参数错误的提示,这时我们可以参考下面的配置,将方法注释中的参数错误的提示,更新为警告提示~~ 具体使用方法,参考下图~
- java基础知识(15)----StringBuffer与StringBuilder
StringBuffer字符串缓冲区: 构造一个其中不带字符的字符串缓冲区,初始容量为 16 个字符.特点:1:可以对字符串内容进行修改.2:是一个容器.3:是可变长度的.4:缓冲区中可以存储任意类型 ...
- 2016.2.24 利用用户控件和委托完美解决快速选择txbbox
1.首先将tet_box和一个datagridview控件打包成用户控件uC_QuickTxtBox 2.在用户控件中定义执行主窗口的委托函数 3.主窗体中添加用户控件的load事件,赋值 uC_Qu ...
- DAY7-面向对象之绑定方法与非绑定方法
一.类中定义的函数分成两大类 一:绑定方法(绑定给谁,谁来调用就自动将它本身当作第一个参数传入): 1. 绑定到类的方法:用classmethod装饰器装饰的方法. 为类量身定制 类.boud_met ...
- DAY7-面向对象之继承与派生
一.初识继承 什么是继承 继承是一种创建新类的方式,新建的类可以继承一个或多个父类(python支持多继承),父类又可称为基类或超类,新建的类称为派生类或子类. 子类会“”遗传”父类的属性,从而解决代 ...
- apache server和tomcat集群配置一:水平负载
下载apache server,最新链接http://archive.apache.org/dist/httpd/binaries/win32 当前实验版本2.2.4 下载apache tomca ...
- oracle行转列练习
----------------------第一题--------------------------- create table STUDENT_SCORE ( name ), subject ), ...
- ae中用粒子系统做的特效怎么循环
- Fiddler系统监控参数解读
转自:https://blog.csdn.net/txj236/article/details/38872855 在对系统监控的过程中,发现ClientConnected和ClientBeginReq ...
- fiddler----APP弱网测试
转自:http://www.51testing.com/html/01/n-3727001.html APP弱网模拟测试 移动端测试区别于PC端测试的一点就是网络的多变性:不同的网络环境和网络制式的差 ...