博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj 3608:Bridge Across Islands
阅读量:6092 次
发布时间:2019-06-20

本文共 2873 字,大约阅读时间需要 9 分钟。

Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 9646   Accepted: 2834   Special Judge

Description

Thousands of thousands years ago there was a small kingdom located in the middle of the Pacific Ocean. The territory of the kingdom consists two separated islands. Due to the impact of the ocean current, the shapes of both the islands became convex polygons. The king of the kingdom wanted to establish a bridge to connect the two islands. To minimize the cost, the king asked you, the bishop, to find the minimal distance between the boundaries of the two islands.

Input

The input consists of several test cases.

Each test case begins with two integers NM. (3 ≤ NM ≤ 10000)
Each of the next N lines contains a pair of coordinates, which describes the position of a vertex in one convex polygon.
Each of the next M lines contains a pair of coordinates, which describes the position of a vertex in the other convex polygon.
A line with N = M = 0 indicates the end of input.
The coordinates are within the range [-10000, 10000].

Output

For each test case output the minimal distance. An error within 0.001 is acceptable.

Sample Input

4 40.00000 0.000000.00000 1.000001.00000 1.000001.00000 0.000002.00000 0.000002.00000 1.000003.00000 1.000003.00000 0.000000 0

Sample Output

  1.00000

 

1 #include
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 #include
9 using namespace std;10 const double eps=1e-8;11 const int maxn=10010;12 int np,nq;13 double ANS;14 struct P{15 double x,y;16 friend P operator-(P a,P b){17 P t; t.x=a.x-b.x; t.y=a.y-b.y;18 return t;19 }20 friend double operator*(P a,P b){ //重载叉乘运算符 21 return a.x*b.y-b.x*a.y;22 }23 friend double operator^(P a,P b){ //重载点乘运算符 24 return a.x*b.x+a.y*b.y; 25 }26 }p[maxn],q[maxn];27 inline double dis(P a,P b){28 return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));29 }30 inline double dotcross(P p0,P p1,P p2){ //向量p0p1 点乘 向量p0p2 31 P t1=p1-p0,t2=p2-p0; 32 return t1^t2;33 }34 inline double difcross(P p0,P p1,P p2){ //向量p0p1 叉乘 向量p0p2 35 P t1=p1-p0,t2=p2-p0; 36 return t1*t2;37 }38 inline double p2seg(P A,P B,P C){ //返回 C到线段 AB的最短距离 39 if(dotcross(A,B,C)<-eps) return dis(A,C);40 if(dotcross(B,A,C)<-eps) return dis(B,C);41 return fabs(difcross(A,B,C)/dis(A,B));42 }43 inline double FourP(P A,P B,P C,P D){44 double ans1=min(p2seg(A,B,C),p2seg(A,B,D));45 double ans2=min(p2seg(C,D,A),p2seg(C,D,B));46 return min(ans1,ans2);47 }48 inline double solve(P p[],P q[],int np,int nq){49 int sp=1,sq=1;50 for(int i=1;i<=np;i++){51 if(p[i].y
q[sq].y) sq=i;55 }56 p[np+1]=p[1]; q[nq+1]=q[1];57 double tmp,ans=1e99;58 for(int i=1;i<=np;i++){ 59 while( tmp=difcross(p[sp+1],q[sq+1],p[sp])-difcross(p[sp+1],q[sq],p[sp])>eps)//tmp

 

 

 

转载于:https://www.cnblogs.com/CXCXCXC/p/5251627.html

你可能感兴趣的文章
Event based Collections
查看>>
例题1-1
查看>>
【leetcode】901. Online Stock Span
查看>>
创建oracle本地数据库步骤详解
查看>>
线段树入门
查看>>
【Android】在某一时间段控制Button是否可点击
查看>>
页面布局
查看>>
svnrdump:E175000:SSL is not supported错误的解决
查看>>
3月23日html(四) 格式与布局
查看>>
http协议
查看>>
《mac的git安装手册-1》
查看>>
MyBatis基础:MyBatis入门(1)
查看>>
nessus安装及使用
查看>>
AspNet GridView Excel 下载 Excel 导出
查看>>
cordova 源码分析记录
查看>>
04 企业的结构
查看>>
php 记录日志时 基础的日志格式
查看>>
dedecms生成文档数据库崩溃 mysql daemon failed to start
查看>>
Linux的50个基本命令
查看>>
Objective-C中创建单例方法的步骤
查看>>