POJ 1279 Art Gallery 半平面交 + 多边形面积
2013-08-29 10:35
369 查看
模板题,没什么好说的。
![](http://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
![](http://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
View Code
![](http://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
![](http://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
View Code
#include<stdio.h> #include<string.h> #include<math.h> #include<algorithm> using namespace std; #define eps 1e-8 struct point { double x, y; }p[1505], tmp[1505], q[1505]; double a, b, c; void get_line(point p1, point p2) { a = p2.y - p1.y; b = p1.x - p2.x; c = p2.x * p1.y - p2.y * p1.x; } point intersect(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 ret; ret.x = (p1.x * v + p2.x * u) / (u + v); ret.y = (p1.y * v + p2.y * u) / (u + v); return ret; } int n, m; void cut() { int tm = 0; int i; for(i = 1; i <= m; i++) { if(a * q[i].x + b * q[i].y + c >= 0) tmp[++tm] = q[i]; else { if(a * q[i-1].x + b * q[i-1].y + c > 0) tmp[++tm] = intersect(q[i-1], q[i]); if(a * q[i+1].x + b * q[i+1].y + c > 0) tmp[++tm] = intersect(q[i], q[i+1]); } } for(i = 1; i <= tm; i++) q[i] = tmp[i]; q[0] = tmp[tm]; q[tm + 1] = tmp[1]; m = tm; } void solve() { int i; for(i = 1; i <= n; i++) q[i] = p[i]; p[n+1] = p[1]; q[0] = q ; q[n+1] = q[1]; m = n; for(i = 1; i <= n; i++) { get_line(p[i], p[i+1]); cut(); } } double cal(int n, point *p) { int i; double s = 0; p[n+1] = p[1]; for(i = 1; i <= n; i++) s += p[i].x * p[i+1].y - p[i].y * p[i+1].x; return fabs(s) / 2; } int main() { int i, j, cas; scanf("%d", &cas); while(cas--) { scanf("%d", &n); for(i = 1;i <= n; i++) scanf("%lf%lf", &p[i].x, &p[i].y); solve(); if(m >= 3)printf("%.2f\n", cal(m, q) ); else printf("0.00\n"); } return 0; }
相关文章推荐
- POJ 1279 Art Gallery(半平面交求多边形核的面积)
- POJ-1279 Art Gallery(求多边形内核面积,半平面交)
- poj 1279 Art Gallery(求多边形核的面积+半平面交)
- POJ 1279 Art Gallery 半平面交+求多边形核的面积
- POJ 1279 Art Gallery 半平面交 + 多边形面积
- poj 1279 Art Gallery(半平面交求多边形核面积)
- poj 1279 Art Gallery - 求多边形核的面积
- poj 1279 Art Gallery - 求多边形核的面积
- POJ 1279 || Art Gallery(半平面交求核面积
- POJ 1279 Art Gallery 半平面交求面积
- POJ 1279 Art Gallery 多边形内核面积
- POJ 1279 Art Gallery(半平面交求多边形核)
- poj 1279 Art Gallery(多边形的核的面积)
- poj1279-Art Gallery 直线围成的区域的面积(半平面交模板题)
- POJ 1279 Art Gallery (半平面交求内核面积)
- POJ 1279 Art Gallery 半平面交求多边形核
- POJ 1279 Art Gallery (多边形组成的内核面积)
- POJ 1279 Art Gallery 半平面交 多边形的核
- poj 1279 Art Gallery(半平面交)
- Poj 1279 Art Gallery (多边形求核)