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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

hdu-1392 Surround the Trees poj Rope (简单凸包)

發布時間:2025/3/16 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 hdu-1392 Surround the Trees poj Rope (简单凸包) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

hdu ?:?http://acm.hdu.edu.cn/showproblem.php?pid=1392? ?

題意:給你n個數的坐標,用一根繩子把它們圍起來,問你需要多長的繩子?

(當數的個數為2時特判 即兩點的距離,這是因為一條直線不應再回去圍了)

題解:簡單的凸包;

code:

#include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #include<cmath> using namespace std; #define eps 1e-6 int top , n; //點 struct POINT {double x, y;POINT(){ }POINT(double a, double b){x = a;y = b;} }p[105],st[105]; //線段 struct Seg {POINT a, b;Seg() { }Seg(POINT x, POINT y){a = x;b = y;} }; //叉乘 double cross(POINT o, POINT a, POINT b) {return (a.x - o.x) * (b.y - o.y) - (b.x - o.x) * (a.y - o.y); }//多邊形面積,需要有順序,順(逆)時針。double area() {double ans = 0;for(int i = 1; i < top; i ++){ans += cross(p[0], p[i], p[i + 1]);}return ans; } //找凸包基點排序 bool cmp0(POINT a, POINT b) {if(a.y < b.y) return true;else if(a.y == b.y && a.x < b.x) return true;return false; } double dis(POINT a,POINT b){return sqrt( (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y) ); } //極角排序 bool cmp1(POINT a, POINT b) {if(cross(p[0], a, b) > eps) return true;else if(fabs(cross(p[0], a, b)) < eps && dis(p[0], a) - dis(p[0], b) > eps) return true;return false; } //Graham_scan 求凸包.所求為純凈凸包... void Graham_scan() {sort(p, p + n, cmp0);sort(p + 1, p + n, cmp1);top = 0;p[n] = p[0];st[top ++] = p[0]; st[top ++] = p[1];for(int i = 2; i <= n; i ++){while(top > 2 && (cross(st[top - 1], st[top - 2], p[i]) > eps || fabs(cross(st[top - 1], st[top - 2], p[i])) < eps)) top --;st[top ++] = p[i];}top --; }int main(){while(scanf("%d",&n),n){for(int i = 0;i < n;i++)scanf("%lf %lf",&p[i].x,&p[i].y);if(n == 2) {printf("%.2lf\n",dis(p[0],p[1]));continue;}Graham_scan();double sumd = 0;for(int i = 0;i < top;i++)sumd += dis(st[i],st[i+1]);printf("%.2lf\n",sumd);} }

poj ? :?http://poj.org/problem?id=2365??

題意:類似于上題,不過會多加一個圓的周長,因為繩子是繞圓柱的圍成多邊形后即多了一個圓的周長;


總結

以上是生活随笔為你收集整理的hdu-1392 Surround the Trees poj Rope (简单凸包)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。