[poj1279]Art Gallery
2024-09-26 21:05:52
题意:求多边形的核的面积。
敲一下半平面交模板........ 然后我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 ;
}
最新文章
- Bash 中的环境变量
- mysql workbench is well-designed
- ServiceStack.Redis 使用教程
- 查看Linux下*.a库文件中文件、函数、变量等情况
- 一款基于css3的3D图片翻页切换特效
- 【Java Web】Eclipse中配置Marven环境
- aaalogo写入中文出错的解决方法
- PHP随机生成指定时间段的指定个数时间
- PAT 团体程序设计天梯赛-练习集 L1-016. 查验身份证
- Maven第一篇【介绍、安装、结构目录】
- Oracle-表被锁住
- java学习——java按值传递和按址传递
- Windows编译OpenCV4Android解决undefined reference to std错误
- css 通配符选择器
- ERP口碑订单无法落桌的解决方法
- P2257 YY的GCD--洛谷luogu
- Flutter路由跳转及参数传递
- TP5.1 钩子与行为应用
- BOM (字节顺序标记)
- java 之多线程