[poj1279]Art Gallery
题意:求多边形的核的面积。
敲一下半平面交模板........ 然后我wa了一早上就因为写了%lf 不知道poj什么破机制还不能用lf的,真的想跳楼
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#define MN 50000
#define eps 1e-10
using namespace std;
inline int read()
{
int x = , f = ; char ch = getchar();
while(ch < '' || ch > ''){ if(ch == '-') f = -; ch = getchar();}
while(ch >= '' && ch <= ''){x = x * + ch - '';ch = getchar();}
return x * f;
} struct P{
double x,y;
P(double _x=,double _y=):x(_x),y(_y){}
P operator + (P b) {return P(x+b.x,y+b.y);}
P operator - (P b) {return P(x-b.x,y-b.y);}
P operator * (double b) {return P(x*b,y*b);}
friend double cross(P a,P b) {return a.x*b.y-b.x*a.y;}
}p[MN+],pt[MN+]; struct L{
P p,v;double slop;
L(){}
L(P x,P y):p(x),v(y){slop=atan2(y.y,y.x);}
P operator * (L b){P a=p-b.p;double t=cross(b.v,a)/cross(v,b.v);return p+v*t;}
bool left(P b){ return cross(v,b-p)>eps;}
bool operator < (const L &y) const {return slop<y.slop;}
}s[MN+],q[MN+]; int n,top,tail; void solve()
{
q[top=tail=]=s[];
for(int i=;i<=n;i++)
{
while(top>tail&&!s[i].left(p[top])) --top;
while(top>tail&&!s[i].left(p[tail+])) ++tail;
if(fabs(s[i].slop-q[top].slop)<eps)
q[top]=s[i].left(q[top].p)?q[top]:s[i];
else q[++top]=s[i];
p[top]=q[top]*q[top-];
}
while(tail<top&&(q[tail].left(p[top])==)) --top;
} int main()
{
for(int T=read();T;T--)
{
n=read();
for(int i=;i<=n;i++) scanf("%lf%lf",&pt[i].x,&pt[i].y);
for(int i=;i<=n;i++) s[i]=L(pt[i-],pt[i]-pt[i-]);
s[]=L(pt[n],pt[]-pt[n]);
sort(s+,s+n+); solve();
if(top-tail+<)
{
for(int i=;i<n;i++) s[i]=L(pt[i+],pt[i]-pt[i+]);
s[n]=L(pt[],pt[n]-pt[]);
sort(s+,s+n+);solve();
}
if(top-tail+<) puts("0.00");
else
{
p[tail]=q[tail]*q[top];double area=;
for(int i=tail;i<top;i++) area+=cross(p[i],p[i+]);
area+=cross(p[top],p[tail]);
printf("%.2f\n",fabs(area)/2.00+eps);
}
}
return ;
}
[poj1279]Art Gallery的更多相关文章
- 再来一道测半平面交模板题 Poj1279 Art Gallery
地址:http://poj.org/problem?id=1279 题目: Art Gallery Time Limit: 1000MS Memory Limit: 10000K Total Su ...
- POJ1279 Art Gallery 多边形的核
POJ1279 给一个多边形 求它的核的面积 所谓多边形的核 是多边形中的一个点集 满足其中的点与多边形边上的点的连线全部在多边形中 用多边形的每一条边所在的直线去切整个坐标平面 得到的一个凸包就是核 ...
- poj 1279 -- Art Gallery (半平面交)
鏈接:http://poj.org/problem?id=1279 Art Gallery Time Limit: 1000MS Memory Limit: 10000K Total Submis ...
- poj 1279 Art Gallery - 求多边形核的面积
/* poj 1279 Art Gallery - 求多边形核的面积 */ #include<stdio.h> #include<math.h> #include <al ...
- 【POJ】【2068】Art Gallery
计算几何/半平面交 裸的半平面交,关于半平面交的入门请看神犇博客:http://blog.csdn.net/accry/article/details/6070621 然而代码我是抄的proverbs ...
- Narrow Art Gallery
Time Limit: 4000ms, Special Time Limit:10000ms, Memory Limit:65536KB Total submit users: 11, Accepte ...
- poj 1279 Art Gallery (Half Plane Intersection)
1279 -- Art Gallery 还是半平面交的问题,要求求出多边形中可以观察到多边形所有边的位置区域的面积.其实就是把每一条边看作有向直线然后套用半平面交.这题在输入的时候应该用多边形的有向面 ...
- POJ1279:Art Gallery——题解
http://poj.org/problem?id=1279 题目大意:给按照顺时针序的多边形顶点,问其内核可行区域面积. —————————————————————————————— 终于变了一点… ...
- UVA 10078 The Art Gallery
Problem: Century Arts has hundreds of art galleries scattered all around the country and you are hir ...
随机推荐
- 关于collectionView和tableView的两种cell的出列方法的区别
相信好多人一定会对collectionView和tableView的两种cell出列方法有所疑问,下面以UICollection为例子进行举例说明 假设我们已经创建了一个collectionView, ...
- style scoped
scoped: 只在父div和其内容内生效,
- Java可重入锁如何避免死锁
本文由https://bbs.csdn.net/topics/390939500和https://zhidao.baidu.com/question/1946051090515119908.html启 ...
- 分布式系统之消息中间件rabbitmq
分布式系统之消息中间件rabbitmq 博客分类: 感谢: 一般php 用rabbitmq java 用activemq http://spartan1.iteye.com/blog/11802 ...
- 剑指offer-二叉树中和为某一值的路径
题目描述 输入一颗二叉树和一个整数,打印出二叉树中结点值的和为输入整数的所有路径.路径定义为从树的根结点开始往下一直到叶结点所经过的结点形成一条路径. 解题思路 利用前序遍历的思想,定义FindP ...
- AutoCAD中的扩展字典及扩展记录(C#)
在学习CAD扩展记录的过程中,遇到了一些问题,也积累了一些经验,现在给大家分享一些我的学习心得.在学习扩展字典之前需要读者了解cad的组码,也就是DxfCode.感兴趣的也可以了解一下扩展数据的相关内 ...
- kubernetes入门(02)kubernetes的架构
一.kubernetes的主从架构 kubectl,全称 Kubernetes Control Plane,它表示Kubernetes为了实现最终的目标而构建的一组集群范围内的进程,这组进程相互协调, ...
- Spring Security 入门(1-7)Spring Security - Session管理
参考链接:https://xueliang.org/article/detail/20170302232815082 session 管理 Spring Security 通过 http 元素下的子元 ...
- sql server 查询表的创建时间
遇到一情况,前几天创建一个表,但是后来忙别的事情了,现在要用这个表,结果失忆了.....完全想不起来表名. 然后就想办法查询表的创建时间试图找回表名 最后找到了,根据表的创建时间排序,因为平常也用不到 ...
- Python第三方库的安装方法总结
源码安装 很多第三方库都是开源的,几乎都可以在github 或者 pypi上找到源码.找到源码格式大概都是 zip . tar.zip. tar.bz2格式的压缩包.解压这些包,进入解压好的文件夹,通 ...