国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

POJ 3608 Bridge Across Islands

2019-11-08 03:24:23
字體:
供稿:網(wǎng)友

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

Source

POJ Founder Monthly Contest – 2008.06.29, Lei Tao

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

旋轉(zhuǎn)卡殼~

(被%lf卡精度調(diào)了三個小時是怎樣的一種體驗?)

輸出要用%f,不能用%lf……玄學(xué)問題n號……

因為題中已經(jīng)給出了凸包,所以是不用再自己寫的。直接用旋轉(zhuǎn)卡殼,枚舉每條邊到另一個凸包的距離,更新答案。

注意要分別用兩個凸包卡對方一次!

(最好不要用bool Operator,容易WA……)

詳見:http://blog.csdn.net/acmaker/article/details/3178696~

#include<cstdio>#include<iostream>#include<cmath>using namespace std;#define eps 1e-8const double inf=1e99;int n,m;struct node{	double x,y;}a[10002],c[10002];double dian(node u,node v){	return u.x*v.x+u.y*v.y;}double cha(node u,node v){	return u.x*v.y-u.y*v.x;}double dis(node u){	return sqrt(dian(u,u));}node operator -(node u,node v){	node p;	p.x=u.x-v.x;p.y=u.y-v.y;	return p;}int zer(double u){	if(abs(u)<eps) return 0;	return u<0 ? -1:1;}bool operator ==(node u,node v){	return !zer(u.x-v.x) && !zer(u.y-v.y);}double cal(node p,node u,node v){	if(u==v) return dis(p-u);	node x1=p-u,x2=p-v,x3=v-u;	if(zer(dian(x2,x3))>0) return dis(x2);	if(zer(dian(x1,x3))<0) return dis(x1);	return abs(cha(x1,x3)/dis(x3));}double findd(node u[],int n,node v[],int m){	int j=1,k=1,kkz;double ans=inf;	for(int i=2;i<=n;i++) if(u[i].y<u[j].y) j=i;	for(int i=2;i<=m;i++) if(v[i].y>v[k].y) k=i;	for(int i=1;i<=n;i++)	{		while((kkz=zer(cha((u[j+1]-u[j]),(v[k]-v[k+1]))))<0) k=k%m+1;		if(!kkz)		{			ans=min(ans,min(cal(u[j],v[k],v[k+1]),cal(u[j+1],v[k],v[k+1])));			ans=min(ans,min(cal(v[k],u[j],u[j+1]),cal(v[k+1],u[j],u[j+1])));		}		else ans=min(ans,cal(v[k],u[j],u[j+1]));		j=j%n+1;	}	return ans;}int main(){	while(scanf("%d%d",&n,&m)==2 && n)	{		for(int i=1;i<=n;i++) scanf("%lf%lf",&a[i].x,&a[i].y);a[n+1]=a[1];		for(int i=1;i<=m;i++) scanf("%lf%lf",&c[i].x,&c[i].y);c[m+1]=c[1];		double ans=min(findd(a,n,c,m),findd(c,m,a,n));		PRintf("%.5f/n",ans);	}	return 0;}


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 岑溪市| 开化县| 黄平县| 巫山县| 兰溪市| 星子县| 华容县| 沈丘县| 柏乡县| 定陶县| 富平县| 三明市| 英山县| 东兴市| 中宁县| 杨浦区| 贡山| 昂仁县| 神木县| 宝兴县| 三台县| 项城市| 桑日县| 石渠县| 云安县| 桦甸市| 宜宾市| 宿州市| 微博| 彝良县| 万载县| 六盘水市| 磐安县| 上栗县| 海宁市| 嘉善县| 康保县| 东丽区| 博兴县| 镇赉县| 宿州市|