日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

poj 2187 Beauty Contest(凸包求解多节点的之间的最大距离)

發(fā)布時間:2025/3/8 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 poj 2187 Beauty Contest(凸包求解多节点的之间的最大距离) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
1 /* poj 2187 Beauty Contest 2 凸包:尋找每兩點之間距離的最大值 3 這個最大值一定是在凸包的邊緣上的! 4 5 求凸包的算法: Andrew算法! 6 */ 7 #include<iostream> 8 #include<cstdio> 9 #include<cstring> 10 #include<algorithm> 11 using namespace std; 12 13 struct Point{ 14 Point(){} 15 Point(int x, int y){ 16 this->x=x; 17 this->y=y; 18 } 19 int x, y; 20 21 static int cross(Point a, Point b){ 22 return a.x*b.y - a.y*b.x; 23 } 24 25 static int dist(Point a, Point b){ 26 return (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y); 27 } 28 29 Point operator -(Point tmp){ 30 return Point(x-tmp.x, y-tmp.y); 31 } 32 }; 33 34 bool cmp(Point a, Point b){ 35 if(a.x==b.x) 36 return a.y<b.y; 37 return a.x<b.x; 38 } 39 40 Point p[50005]; 41 int ch[50005]; 42 int n; 43 44 int main(){ 45 int i; 46 while(scanf("%d", &n)!=EOF){ 47 for(i=0; i<n; ++i) 48 scanf("%d%d", &p[i].x, &p[i].y); 49 sort(p, p+n, cmp); 50 int m=0; 51 //求下凸包, 如果某一個點不在線段之內(nèi),向量的叉積必定是<=0; 52 for(i=0; i<n; ++i){ 53 while(m>1 && Point::cross(p[ch[m-1]]-p[ch[m-2]], p[i]-p[ch[m-2]])<=0) m--; 54 ch[m++]=i; 55 } 56 //為啥求上凸包的時候,坐標(biāo)的從n-2開始:因為n-1點一定是在下凸包中的(因為它的橫坐標(biāo)最大,必然是包含其他節(jié)點的) 57 int k=m; 58 for(i=n-2; i>=0; --i){ 59 while(m>k && Point::cross(p[ch[m-1]]-p[ch[m-2]], p[i]-p[ch[m-2]])<=0) m--; 60 ch[m++]=i; 61 } 62 --m; 63 int maxD=-1, j, d; 64 for(i=0; i<m; ++i) 65 for(j=i+1; j<=m; ++j) 66 if(maxD < (d=Point::dist(p[ch[i]], p[ch[j]]))) 67 maxD=d; 68 printf("%d\n", maxD); 69 } 70 return 0; 71 }

?

轉(zhuǎn)載于:https://www.cnblogs.com/hujunzheng/p/3879221.html

總結(jié)

以上是生活随笔為你收集整理的poj 2187 Beauty Contest(凸包求解多节点的之间的最大距离)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。