POJ 1279 Art Gallery (半平面交求面积)
来源:互联网 发布:java 写入word文档 编辑:程序博客网 时间:2024/05/19 12:28
Art Gallery
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 6318 Accepted: 2627
Description
The art galleries of the new and very futuristic building of the Center for Balkan Cooperation have the form of polygons (not necessarily convex). When a big exhibition is organized, watching over all of the pictures is a big security concern. Your task is that for a given gallery to write a program which finds the surface of the area of the floor, from which each point on the walls of the gallery is visible. On the figure 1. a map of a gallery is given in some co-ordinate system. The area wanted is shaded on the figure 2.
Input
The number of tasks T that your program have to solve will be on the first row of the input file. Input data for each task start with an integer N, 5 <= N <= 1500. Each of the next N rows of the input will contain the co-ordinates of a vertex of the polygon ? two integers that fit in 16-bit integer type, separated by a single space. Following the row with the co-ordinates of the last vertex for the task comes the line with the number of vertices for the next test and so on.
Output
For each test you must write on one line the required surface - a number with exactly two digits after the decimal point (the number should be rounded to the second digit after the decimal point).
Sample Input
170 04 44 79 713 -18 -64 -4
Sample Output
80.00ac代码:#include<stdio.h>#include<math.h>#include<string.h>#include<stack>#include<queue>#include<vector>#include<iostream>#include<algorithm>#define MAXN 60001#define LL long long#define INF 0xfffffff#define mem(aa) memset(aa,0,sizeof(aa))#define PI acos(-1)#define eps 1e-8using namespace std;struct s{double x,y;};s list[MAXN],p[MAXN],q[MAXN];double a,b,c,area;int cnt,ccnt,n;void getline(s x,s y){a=y.y-x.y;b=x.x-y.x;c=y.x*x.y-x.x*y.y;}s xlist(s x,s y){double u=fabs(a*x.x+b*x.y+c);double v=fabs(a*y.x+b*y.y+c);s k;k.x=(x.x*v+y.x*u)/(u+v);k.y=(x.y*v+y.y*u)/(u+v);return k;}void cut(){ccnt=0;for(int i=1;i<=cnt;i++){if(a*p[i].x+b*p[i].y+c>=0)q[++ccnt]=p[i];else{if(a*p[i-1].x+b*p[i-1].y+c>0)q[++ccnt]=xlist(p[i],p[i-1]);if(a*p[i+1].x+b*p[i+1].y+c>0)q[++ccnt]=xlist(p[i],p[i+1]);}}for(int i=1;i<=ccnt;i++)p[i]=q[i];p[ccnt+1]=q[1];p[0]=p[ccnt];cnt=ccnt;}void solve(){int i;for(i=1;i<=n;i++)p[i]=list[i];p[n+1]=p[1];p[0]=p[n];cnt=n;for(i=1;i<=n;i++){getline(list[i],list[i+1]);cut();}area=0;for(i=1;i<=ccnt;i++)area+=p[i].x*p[i+1].y-p[i+1].x*p[i].y;area=fabs(area/2.0);}void guizheng(){for(int i=1;i<(n+1)/2;i++)swap(list[i],list[n-i]);}int main(){int t,i;scanf("%d",&t);while(t--){scanf("%d",&n);for(i=1;i<=n;i++)scanf("%lf%lf",&list[i].x,&list[i].y);list[n+1]=list[1];solve();printf("%.2lf\n",area);}return 0;}
0 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(求多边形内核面积,半平面交)
- 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 (半平面交)
- poj 1279 Art Gallery(半平面交)
- POJ 1279 Art Gallery (计算几何+半平面交)
- POJ 1279 || Art Gallery(半平面交求核面积
- 青春生活的苦与甜
- 【HBOI2013】Eden的博弈树
- 为什么HTML5移动应用程序名声不好?
- mysql 创建用户和密码提示失败
- 10: const 常量
- POJ 1279 Art Gallery (半平面交求面积)
- 从零开始快速搭建Android应用自动化测试(一)
- SecurePreference的添加方法
- NETCTOSS03_登陆模块
- C语言二维数组
- Spring整合LogBack
- html5语义化标签
- String,StringBuffer与StringBuilder的区别??
- JAVA的StringBuffer类