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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

poj 3348 Cows 求凸包以及凸包的面积

發布時間:2023/11/29 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 poj 3348 Cows 求凸包以及凸包的面积 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題目來源:

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

1:任意多邊形p[0,n-1]的面積為

for(int i=0 ; i<=n-1 ; i++){
sum+= (sk[i]^sk[(i+1)%(n) ] )*0.5;
}

2: 求凸包, 用graham 模板

代碼如下:

#include <iostream> #include <algorithm> #include <stdlib.h> #include <iostream> #include <stdio.h> #include <stack> #include <string> #include <string.h> #include <algorithm> #include <stdlib.h> #include <vector> #include <set> #include <math.h> #include <cmath> #include <map> #include <queue> using namespace std ; typedef long long LL; const int N = 10010; double EPS= 1e-10; double add(double a, double b) {if( fabs(a+b)< EPS * ( fabs(a)+fabs(b) ) ) return 0;return a+b; } struct Point{double x,y;Point(){}Point(double _x, double _y):x(_x),y(_y){}Point operator + (Point p){return Point( add(x,p.x), add( y,p.y ) );}Point operator -(Point p){return Point( add(x,-p.x), add(y, -p.y) );}double operator^(Point p){return add(x*p.y, -y*p.x );}friend istream& operator>>(istream& is, Point& p){is>>p.x>>p.y;return is;}double dist(Point p){return sqrt( add( ( x-p.x)*(x-p.x) , (y-p.y)*(y-p.y) ) );} }; Point List[N]; // 點集 int top; // 棧頂指針 Point sk[N]; // bool cmp(Point a, Point b) // 按y軸值從小到大, y軸值相同時,x軸從小到大排列 {if(a.y != b.y) return a.y < b.y;else return a.x < b.x; } bool operator < (Point a, Point b) // 極角排序 {double tmp= (a-List[0])^(b-List[0]);if(tmp > 0) return 1;else if(tmp== 0 && a.dist(List[0]) <b.dist(List[0]) ) return 1;return 0; } void init(int n) {for(int i=0 ; i<n ;i++)cin>>List[i];sort(List, List+n,cmp);// 排序后 List[0]為最左下方的點sort(List+1 , List+n ); // 對List[1,n-1] 中的點進行極角排序,為凸包做準備 } void graham(int n) {sk[0]=List[0];sk[1]=List[1];top=1;double t;for(int i=2 ; i< n ; i++){while(top >= 1 && ( (sk[top]-sk[top-1] )^(List[i]-sk[top-1] ) ) <=0 )top--; // 不是凸包中的點出棧top++;// 點i進棧sk[top]=List[i];} } int main() {int n;cin>>n;init(n);graham(n);double sum=0.0;for(int i=0 ; i<=top ; i++){sum+= (sk[i]^sk[(i+1)%(top+1) ] )*0.5;}printf("%d\n",(int)sum/50);return 0; }

?

轉載于:https://www.cnblogs.com/zn505119020/p/3644606.html

總結

以上是生活随笔為你收集整理的poj 3348 Cows 求凸包以及凸包的面积的全部內容,希望文章能夠幫你解決所遇到的問題。

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