博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj 1279 半平面交核面积
阅读量:6332 次
发布时间:2019-06-22

本文共 4428 字,大约阅读时间需要 14 分钟。

Art Gallery
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 6668   Accepted: 2725

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

 

/*poj 1279 半平面交核面积给你一个多边形的图书馆.要求得到一块地方能看见墙上所有的点,并求出面积在半平面模板上加个求面积公式即可.而且输入并没有指定顺时针还是逆时针,可以通过求面积进行判断.hhh-2016-05-11 21:01:47*/#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;#define lson (i<<1)#define rson ((i<<1)|1)typedef long long ll;using namespace std;const int maxn = 1510;const double PI = 3.1415926;const double eps = 1e-8;int sgn(double x){ if(fabs(x) < eps) return 0; if(x < 0) return -1; else return 1;}struct Point{ double x,y; Point() {} Point(double _x,double _y) { x = _x,y = _y; } Point operator -(const Point &b)const { return Point(x-b.x,y-b.y); } double operator ^(const Point &b)const { return x*b.y-y*b.x; } double operator *(const Point &b)const { return x*b.x + y*b.y; }};struct Line{ Point s,t; double k; Line() {} Line(Point _s,Point _t) { s = _s; t = _t; k = atan2(t.y-s.y,t.x-s.x); } Point operator &(const Line &b) const { Point res = s; double ta = ((s-b.s)^(b.s-b.t))/((s-t)^(b.s-b.t)); res.x += (t.x-s.x)*ta; res.y += (t.y-s.y)*ta; return res; }};bool HPIcmp(Line a,Line b){ if(fabs(a.k-b.k) > eps) return a.k
< n;i++) { ans += (p[i]^p[(i+1)%n])/2; } return ans;}double HPI(Line line[],int n,Point res[],int &resn){ int tot =n; sort(line,line+n,HPIcmp); tot = 1; for(int i = 1; i < n; i++) { if(fabs(line[i].k - line[i-1].k) > eps) line[tot++] = line[i]; } int head = 0,tail = 1; li[0] = line[0]; li[1] = line[1]; resn = 0; for(int i = 2; i < tot; i++) { if(fabs((li[tail].t-li[tail].s)^(li[tail-1].t-li[tail-1].s)) < eps|| fabs((li[head].t-li[head].s)^(li[head+1].t-li[head+1].s)) < eps) return 0; while(head < tail && (((li[tail] & li[tail-1]) - line[i].s) ^ (line[i].t-line[i].s)) > eps) tail--; while(head < tail && (((li[head] & li[head+1]) - line[i].s) ^ (line[i].t-line[i].s)) > eps) head++; li[++tail] = line[i]; } while(head < tail && (((li[tail] & li[tail-1]) - li[head].s) ^ (li[head].t-li[head].s)) > eps) tail--; while(head < tail && (((li[head] & li[head-1]) - li[tail].s) ^ (li[tail].t-li[tail].t)) > eps) head++; if(tail <= head+1) return 0; for(int i = head; i < tail; i++) res[resn++] = li[i]&li[i+1]; if(head < tail-1) res[resn++] = li[head]&li[tail]; double tans = 0; for(int i = 0;i < resn;i++) { tans += (res[i]^res[(i+1)%resn])/2; } return fabs(tans);}Point p0;Point lis[maxn];Line line[maxn];double dist(Point a,Point b){ return sqrt((a-b)*(a-b));}bool cmp(Point a,Point b){ double t = (a-p0)^(b-p0); if(sgn(t) > 0)return true; else if(sgn(t) == 0 && sgn(dist(a,lis[0])-dist(b,lis[0])) <= 0) return true; else return false;}int main(){ //freopen("in.txt","r",stdin); int n,T; scanf("%d",&T); while(T--) { scanf("%d",&n); for(int i = 0; i < n; i++) { scanf("%lf%lf",&lis[i].x,&lis[i].y); } int ans; if(CalArea(lis,n) < 0) reverse(lis,lis+n); for(int i = 0; i < n; i++) { line[i] = Line(lis[i],lis[(i+1)%n]); } printf("%.2f\n",HPI(line,n,lis,ans)); } return 0;}

  

转载于:https://www.cnblogs.com/Przz/p/5510568.html

你可能感兴趣的文章
第二十四章:页面导航(六)
查看>>
百度、长沙加码自动驾驶,湖南阿波罗智行科技公司成立 ...
查看>>
Java面试笔试题大汇总一(最全+详细答案)
查看>>
10 个 Linux 中方便的 Bash 别名
查看>>
[Server] 服务器配置SSH登录邮件通知
查看>>
全新 DOCKER PALS 计划上线,带给您不一样的参会体验! ...
查看>>
Android开发之自定义View(二)
查看>>
python爬虫之微打赏(scrapy版)
查看>>
自制操作系统Antz day08——实现内核 (中) 扩展内核
查看>>
poj-1056-IMMEDIATE DECODABILITY(字典)
查看>>
阿里云容器Kubernetes监控(二) - 使用Grafana展现Pod监控数据
查看>>
区块链应用 | 不知道什么时候起,满世界都在谈区块链的事情
查看>>
小程序爆红 专家:对简单APP是巨大打击
查看>>
FarBox--另类有趣的网站服务【转】
查看>>
在非纯色背景上,叠加背景透明的BUTTON和STATIC_TEXT控件
查看>>
Distributed2:Linked Server Login 添加和删除
查看>>
海量数据处理相关面试问题
查看>>
Python-time
查看>>
Java中取两位小数
查看>>
RTX发送消息提醒实现以及注意事项
查看>>