[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 ...
随机推荐
- bzoj千题计划242:bzoj4034: [HAOI2015]树上操作
http://www.lydsy.com/JudgeOnline/problem.php?id=4034 dfs序,树链剖分 #include<cstdio> #include<io ...
- Codeforces 193 D. Two Segments
http://codeforces.com/contest/193/problem/D 题意: 给一个1~n的排列,在这个排列中选出两段区间,求使选出的元素排序后构成公差为1的等差数列的方案数. 换个 ...
- java8-Stream之数值流
在Stream里元素都是对象,那么,当我们操作一个数字流的时候就不得不考虑一个问题,拆箱和装箱.虽然自动拆箱不需要我们处理,但依旧有隐含的成本在里面.Java8引入了3个原始类型特化流接口来解决这个问 ...
- jQuery 写的textarea输入字数限制
//先判断浏览器是不是万恶的IE var bind_name = 'input';//默认事件 if (navigator.userAgent.indexOf(" ...
- LDAP是什么
LDAP的英文全称是Lightweight Directory Access Protocol,一般都简称为LDAP.LDAP目录服务是一种特殊的数据库系统,其专门针对读取,浏览和搜索操作进行了特定的 ...
- Spring Security 入门(3-11)Spring Security 的登录密码验证过程 UsernamePasswordAuthenticationFilter
认证过程如下 一.先判断请求(请求必须是post请求)地址是否为配置的 login-processing-url 值(默认/j_spring_security_check),如果不是,则放行,进入下一 ...
- Spring Security入门(3-8)Spring Security获取session中的UserDetail
- 译《Time, Clocks, and the Ordering of Events in a Distributed System》
Motivation <Time, Clocks, and the Ordering of Events in a Distributed System>大概是在分布式领域被引用的最多的一 ...
- [洛谷P2234][HNOI2002] 营业额统计 - Treap
Description Tiger最近被公司升任为营业部经理,他上任后接受公司交给的第一项任务便是统计并分析公司成立以来的营业情况. Tiger拿出了公司的账本,账本上记录了公司成立以来每天的营业额. ...
- Web开发笔记
jquery ui draggable clone之后不会克隆draggable功能,要重新设置