日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) >

P2742-二维凸包/圈奶牛Fencing the Cows【凸包】

發(fā)布時(shí)間:2023/12/3 55 豆豆
生活随笔 收集整理的這篇文章主要介紹了 P2742-二维凸包/圈奶牛Fencing the Cows【凸包】 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

正題

題目鏈接:https://www.luogu.org/recordnew/lists?uid=SSL_WYC_zombieeeeee&pid=P2742&status=&sort=0


題目大意

求凸包總長(zhǎng)度


解題思路

求凸包


codecodecode

#include<cstdio> #include<algorithm> #include<cmath> #define N 10010 using namespace std; struct point{double x,y; }a[N]; int n,s[N]; double ans; double m(point x,point y,point z) {return (x.x-z.x)*(y.y-z.y)-(y.x-z.x)*(x.y-z.y);} double dis(point x,point y) {return sqrt((x.x-y.x)*(x.x-y.x)+(x.y-y.y)*(x.y-y.y));} bool cmp(point x,point y) {double t=m(x,y,a[1]);if(t>0||t==0&&dis(x,a[1])<dis(y,a[1]))return true;else return false; } void init() {scanf("%d",&n);for(int i=1;i<=n;i++){scanf("%lf%lf",&a[i].x,&a[i].y);if(a[i].y<a[1].y||a[i].y==a[1].y&&a[i].x<a[1].x)swap(a[i],a[1]);}sort(a+2,a+1+n,cmp); } void praham() {s[1]=1;s[2]=2;s[3]=3;int top=3;for(int i=4;i<=n;i++){while(m(a[i],a[s[top]],a[s[top-1]])>=0)top--;s[++top]=i;}for(int i=1;i<top;i++)ans+=dis(a[s[i]],a[s[i+1]]);printf("%.2lf",ans+dis(a[s[1]],a[s[top]])); } int main() {init();praham(); }

總結(jié)

以上是生活随笔為你收集整理的P2742-二维凸包/圈奶牛Fencing the Cows【凸包】的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

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