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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

POJ 1279 Art Gallery 半平面交 多边形的核

發布時間:2025/4/5 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 POJ 1279 Art Gallery 半平面交 多边形的核 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題意:求多邊形的核的面積

套模板即可

#include <iostream> #include <cstdio> #include <cmath> #define eps 1e-18 using namespace std;const int MAXN = 1555; double a, b, c; int n, cnt;struct Point {double x, y;double operator ^(const Point &b) const{return x*b.y - y*b.x;} }point[MAXN], p[MAXN], tp[MAXN];void Get_equation(Point p1, Point p2) {a = p2.y - p1.y;b = p1.x - p2.x;c = p2.x * p1.y - p1.x * p2.y; }Point Intersection(Point p1, Point p2) {double u = fabs(a * p1.x + b * p1.y + c);double v = fabs(a * p2.x + b * p2.y + c);Point t;t.x = (p1.x * v + p2.x * u) / (u + v);t.y = (p1.y * v + p2.y * u) / (u + v);return t; }void Cut() {int tmp = 0;for(int i=1; i<=cnt; i++){//順時針是>-eps和>eps,逆時針是<eps和<-epsif(a * p[i].x + b * p[i].y + c > -eps) tp[++tmp] = p[i];else{if(a * p[i-1].x + b * p[i-1].y + c > eps)tp[++tmp] = Intersection(p[i-1], p[i]);if(a * p[i+1].x + b * p[i+1].y + c > eps)tp[++tmp] = Intersection(p[i], p[i+1]);}}for(int i=1; i<=tmp; i++)p[i] = tp[i];p[0] = p[tmp];p[tmp+1] = p[1];cnt = tmp; }double solve() {for(int i=1; i<=n; i++)p[i] = point[i];point[n+1] = point[1];p[0] = p[n];p[n+1] = p[1];cnt = n;for(int i=1; i<=n; i++){Get_equation(point[i], point[i+1]);Cut();}double res = 0;for(int i = 1; i <= cnt; i++)res += p[i]^p[i+1];return fabs(res/2); }int main() {int T;scanf("%d\n", &T);while(T--){scanf("%d", &n);for(int i=1; i<=n; i++)scanf("%lf%lf", &point[i].x, &point[i].y);printf("%.2f\n", solve());}return 0; }

?

轉載于:https://www.cnblogs.com/pach/p/7482240.html

總結

以上是生活随笔為你收集整理的POJ 1279 Art Gallery 半平面交 多边形的核的全部內容,希望文章能夠幫你解決所遇到的問題。

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