poj1279Art Gallery【半平面交求内核面积】
来源:互联网 发布:模具erp软件 编辑:程序博客网 时间:2024/05/21 10:12
Language:
Art Gallery
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 6027 Accepted: 2543
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.00
题意:半平面交求内核面积
#include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<algorithm>#define eps 1e-10using namespace std;struct point{double x,y;}A[1510],p[1510],q[1510];int N,tempcnt,endcnt;void init(){for(int i=1;i<=N;++i){p[i]=A[i];}p[N+1]=p[1];p[0]=p[N];endcnt=N;}void getline(point p1,point p2,double &a,double &b,double &c){a=p2.y-p1.y;b=p1.x-p2.x;c=p2.x*p1.y-p2.y*p1.x;}point getinter(point p1,point p2,double a,double b,double c){double u=fabs(a*p1.x+b*p1.y+c);double v=fabs(a*p2.x+b*p2.y+c);point temp;temp.x=(v*p1.x+u*p2.x)/(u+v);temp.y=(v*p1.y+u*p2.y)/(u+v);return temp;}void cut(double a,double b,double c){tempcnt=0;for(int i=1;i<=endcnt;++i){if(a*p[i].x+b*p[i].y+c>=0)q[++tempcnt]=p[i];else {if(a*p[i-1].x+b*p[i-1].y+c>0){q[++tempcnt]=getinter(p[i],p[i-1],a,b,c);}if(a*p[i+1].x+b*p[i+1].y+c>0){q[++tempcnt]=getinter(p[i],p[i+1],a,b,c);}}}for(int i=1;i<=tempcnt;++i){p[i]=q[i];}p[tempcnt+1]=q[1];p[0]=p[tempcnt];endcnt=tempcnt;}void solve(){init();for(int i=1;i<=N;++i){double a,b,c;getline(A[i],A[i+1],a,b,c);cut(a,b,c);}double s=0;for(int i=1;i<=endcnt;++i){s+=p[i].x*p[i+1].y-p[i].y*p[i+1].x;}printf("%.2lf\n",fabs(s/2.0));}int main(){int t,i,j,k;scanf("%d",&t);while(t--){scanf("%d",&N);for(i=1;i<=N;++i){scanf("%lf%lf",&A[i].x,&A[i].y);}A[N+1]=A[1];solve();}return 0;}
0 0
- poj1279Art 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 半平面交 + 多边形面积
- POJ2540-半平面交求线性规划可行区域的面积
- POJ 2540 半平面交求可行区域面积
- poj 1279 求半平面交的 面积(推荐)
- POJ 2451 Uyuw's Concert(半平面交求面积)
- poj2540Hotter Colder【半平面交求线性规划面积】
- POJ 2451 Uyuw's Concert 半平面交求面积
- csu 1812(半平面交求面积)
- 半平面求交
- javascript数组的其他方法
- Linux中的UID,EUID,SUID
- 如何使用C#调用雅虎REST服务
- [HDU 1166]敌兵布阵[树状数组][入门]
- JDBC
- poj1279Art Gallery【半平面交求内核面积】
- 系统调用跟我学之wait, waitpid函数
- hdu 1728 BFS 逃离迷宫 值得注意
- android: java.io.IOException:open failed: ENOENT (No such file or directory)
- 安卓环境搭建须知
- 第五章 RARP:逆地址解析协议
- iPhone屏幕尺寸、分辨率及适配
- xml 笔记
- AppWidget