LA-2512:Art Gallery(半平面交)
来源:互联网 发布:淘宝手机怎么改评论 编辑:程序博客网 时间:2024/05/06 23:26
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.
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.
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).
170 04 44 79 713 -18 -64 -4
80.00
题意:给你一个多边形的画廊,找出一片区域,使得无论你站在这个区域的哪个地方,都能监视到画廊的各个地方。
思路:半平面交的模版题。求出半平面交的面积即可。(题目中给的点是按顺时针方向给出的,不过题目没有说明给出的顺序)
#include<iostream>#include<cstring>#include<algorithm>#include<cstdio>#include<cmath>using namespace std;struct Point{ double x,y;}p[2000],ch[2000];struct Line{ Point p; Point v; double angle; Line(){} Line(Point p,Point v):p(p),v(v){angle=atan2(v.y,v.x);} bool operator<(const Line& L)const{return angle<L.angle;}}L[2000];double cross(Point a,Point b) //ab叉积{return (a.x*b.y-a.y*b.x);}Point Vector(Point a,Point b) //向量ba{Point c;c.x=a.x-b.x;c.y=a.y-b.y;return c;}double Polyarea(Point *p,int n) //求多边形面积{double area=0;for(int i=1;i<n-1;i++){area+=cross(Vector(p[i],p[0]),Vector(p[i+1],p[0]));}return area/2;}bool Onleft(Line L,Point p){return cross(L.v,Vector(p,L.p))>0;}Point Getinter(Line a,Line b){ Point u=Vector(a.p,b.p); double t=cross(b.v,u)/cross(a.v,b.v); return (Point){a.p.x+a.v.x*t,a.p.y+a.v.y*t};}int Half(Line *L,int n,Point *poly) //求半平面交上的点{ sort(L,L+n); int first,last; Point *p=new Point[n]; Line *q=new Line[n]; q[first=last=0]=L[0]; for(int i=1;i<n;i++) { while(first<last&&!Onleft(L[i],p[last-1]))last--; while(first<last&&!Onleft(L[i],p[first]))first++; q[++last]=L[i]; if(fabs(cross(q[last].v,q[last-1].v))<1e-7) { last--; if(Onleft(q[last],L[i].p))q[last]=L[i]; } if(first<last)p[last-1]=Getinter(q[last-1],q[last]); } while(first<last&&!Onleft(q[first],p[last-1]))last--; if(last-first<=1)return 0; p[last]=Getinter(q[last],q[first]); int m=0; for(int i=first;i<=last;i++)poly[m++]=p[i]; return m;}int main(){ int T,n;cin>>T; while(T--) { cin>>n; for(int i=0;i<n;i++)cin>>p[i].x>>p[i].y; for(int i=0;i<n;i++)L[i]=(Line){p[i],Vector(p[i],p[(i+1)%n])}; int m=Half(L,n,ch); printf("%0.2f\n",Polyarea(ch,m)); }return 0;}
阅读全文
1 0
- LA 2512 —— Art Gallery(半平面交)
- LA-2512:Art Gallery(半平面交)
- [POJ1279]Art Gallery(半平面交)
- (beginer) 半平面交 UVA 1304 Art Gallery
- poj 1279 Art Gallery (半平面交)
- poj 1279 Art Gallery(半平面交)
- POJ 1279 Art Gallery (计算几何+半平面交)
- POJ 1279 Art Gallery(半平面交)
- LA2512 Art Gallery 半平面交
- poj 1279 Art Gallery 半平面交
- [POJ 1279]Art Gallery:半平面交
- POJ 1279 Art Gallery [半平面交]
- LA 2512 半平面交
- poj1279——Art Gallery//半平面交 求面积
- POJ 1279 Art Gallery 半平面交 + 多边形面积
- POJ 1279 Art Gallery (半平面交求面积)
- POJ 1279 Art Gallery 半平面交求面积
- zoj 1369 || poj 1279 Art Gallery(半平面交第一题~~嘿嘿~)
- yum源配置
- Oracle数据库数据同步方法
- 线程进程同步(占坑)
- spring mvc redirect 重定向 跳转并传递参数
- Git学习
- LA-2512:Art Gallery(半平面交)
- 如何搭上AR+快车,ARVR云设计告诉你!
- ZooKeeper之(三)工作原理
- handlebars结合分页插件实现多条件查询
- HDUOJ 1506 Largest Rectangle in a Histogram
- 使用Jquery cookie插件实现用户名和密码的保存
- ETL调优
- NYOJ 456 邮票分你一半
- 因果图:过失