题目大意:有一个N边形展馆,问展馆内有多少地方可以看到所有墙壁。(N<=1500)

思路:模板题,半平面交求出多边形的核后计算核的面积。

#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
inline int read()
{
int x,f=;char c;
while((c=getchar())<''||c>'')if(c=='-')f=;
for(x=c-'';(c=getchar())>=''&&c<='';)x=(x<<)+(x<<)+c-'';
return f?x:-x;
}
#define MN 1500
#define eps 1e-7
struct P{double x,y;}p[MN+];
P operator+(P a,P b){return (P){a.x+b.x,a.y+b.y};}
P operator-(P a,P b){return (P){a.x-b.x,a.y-b.y};}
P operator*(P a,double x){return (P){a.x*x,a.y*x};}
double operator*(P a,P b){return a.x*b.y-a.y*b.x;}
struct line{P p,v;}l[MN+];
bool cmp(line a,line b){return atan2(a.v.y,a.v.x)<atan2(b.v.y,b.v.x);}
int q[MN+],ql,qr;
bool left(line l,P p){return l.v*(p-l.p)>;}
P xp(line a,line b){return a.p+a.v*(b.v*(a.p-b.p)/(a.v*b.v));}
int main()
{
int T=read(),n,i;double ans;
while(T--)
{
n=read();
for(i=;i<n;++i)p[i].x=read(),p[i].y=read();
for(p[n]=p[i=];i<n;++i)l[i].p=p[i+],l[i].v=p[i]-p[i+];
sort(l,l+n,cmp);
for(q[ql=qr=]=,i=;i<n;++i)
{
while(ql<qr&&!left(l[i],p[qr-]))--qr;
while(ql<qr&&!left(l[i],p[ql]))++ql;
if(q[++qr]=i,fabs(l[q[qr]].v*l[q[qr-]].v)<eps)
if(left(l[q[--qr]],l[i].p))q[qr]=i;
if(ql<qr)p[qr-]=xp(l[q[qr-]],l[q[qr]]);
}
while(ql<qr&&!left(l[q[ql]],p[qr-]))--qr;
p[qr]=xp(l[q[qr]],l[q[ql]]);
for(ans=,i=ql;++i<qr;)ans+=(p[i]-p[ql])*(p[i+]-p[ql]);
printf("%.2f\n",fabs(ans)/);
}
}

[POJ]1279: Art Gallery的更多相关文章

  1. poj 1279 Art Gallery - 求多边形核的面积

    /* poj 1279 Art Gallery - 求多边形核的面积 */ #include<stdio.h> #include<math.h> #include <al ...

  2. poj 1279 -- Art Gallery (半平面交)

    鏈接:http://poj.org/problem?id=1279 Art Gallery Time Limit: 1000MS   Memory Limit: 10000K Total Submis ...

  3. poj 1279 Art Gallery (Half Plane Intersection)

    1279 -- Art Gallery 还是半平面交的问题,要求求出多边形中可以观察到多边形所有边的位置区域的面积.其实就是把每一条边看作有向直线然后套用半平面交.这题在输入的时候应该用多边形的有向面 ...

  4. POJ 1279 Art Gallery 半平面交/多边形求核

    http://poj.org/problem?id=1279 顺时针给你一个多边形...求能看到所有点的面积...用半平面对所有边取交即可,模版题 这里的半平面交是O(n^2)的算法...比较逗比.. ...

  5. POJ 1279 Art Gallery(半平面交)

    题目链接 回忆了一下,半平面交,整理了一下模版. #include <cstdio> #include <cstring> #include <string> #i ...

  6. POJ 1279 Art Gallery(半平面交求多边形核的面积)

    题目链接 题意 : 求一个多边形的核的面积. 思路 : 半平面交求多边形的核,然后在求面积即可. #include <stdio.h> #include <string.h> ...

  7. POJ 1279 Art Gallery 半平面交求多边形核

    第一道半平面交,只会写N^2. 将每条边化作一个不等式,ax+by+c>0,所以要固定顺序,方便求解. 半平面交其实就是对一系列的不等式组进行求解可行解. 如果某点在直线右侧,说明那个点在区域内 ...

  8. POJ 1279 Art Gallery【半平面交】(求多边形的核)(模板题)

    <题目链接> 题目大意: 按顺时针顺序给出一个N边形,求N边形的核的面积. (多边形的核:它是平面简单多边形的核是该多边形内部的一个点集该点集中任意一点与多边形边界上一点的连线都处于这个多 ...

  9. POJ 1279 Art Gallery 半平面交 多边形的核

    题意:求多边形的核的面积 套模板即可 #include <iostream> #include <cstdio> #include <cmath> #define ...

随机推荐

  1. Linux下关闭Tomcat残留线程

    ps -ef | grep tomcat kill -9 {pid}

  2. 通过URL传递PDF名称参数显示PDF

    1 <%@ page language="java" import="java.util.*,java.io.*" 2 pageEncoding=&quo ...

  3. 用‘+=’拼接字符串,打印时总会出现一个undefined

    var str; for(var i = 0; i < 5; i++){ str += String(i); } console.log(str); 他喵的,打印的结果竟然是"unde ...

  4. DSkin 的WebUI开发模式介绍,Html快速开发Winform的UI

    新版WebUI开发模式采用MiniBlink内核,这个内核功能更完善,dll压缩之后才5M,而且提供开发者功能,内核还在更新中,而且是开源项目:https://github.com/weolar/mi ...

  5. Redux应用单一的store原则案例详解

    在开发reac单页面应用的时候,页面的展示逻辑跟数据状态的关系管理变得越来越复杂,redux很好的解决这个问题.废话不多说,直接先上官网api链接. http://cn.redux.js.org/in ...

  6. SpringBoot+Angular2 开发环境搭建

    https://segmentfault.com/a/1190000007921675

  7. centos7.0下的 systemctl 用法

    参考链接: http://man.linuxde.net/systemctl

  8. 新概念英语(1-123)A trip to Australia

    Who is the man with the beard?(胡须)A:Look, Scott. This is a photograph I took during my trip to Austr ...

  9. 整理一下 System.Linq.Enumerable 类中的那些比较少用的方法

    Linq 虽然用得多,但是里面有一些方法比较少用,因此整理一下.Enumerable 类的所有方法可以在 MSDN 上查阅到:https://msdn.microsoft.com/zh-cn/libr ...

  10. leetcode算法:Island Perimeter

    You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represen ...