Art Gallery - POJ 1279(求内核面积)
同上面几道题差不多,需要先求出来内核,然后直接用叉积求出来面积即可。
代码如下:
#include<iostream>
#include<string.h>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<queue>
using namespace std; const int MAXN = ;
const int oo = 1e9+;
const double EPS = 1e-; int Sign(double t)
{
if(t > EPS)
return ;
if(fabs(t) < EPS)
return ;
return -;
} struct Point
{
double x, y;
Point(double x=, double y=):x(x),y(y){}
Point operator - (const Point &t)const{
return Point(x-t.x, y-t.y);
}
double operator ^(const Point &t)const{
return x*t.y - y*t.x;
} }p[MAXN], in[MAXN];
struct Segment
{
Point S, E;
double a, b, c;
Segment(Point S=, Point E=):S(S), E(E){
a = S.y - E.y;
b = E.x - S.x;
c = E.x*S.y - S.x*E.y;
}
Point crossNode(const Segment &t)const{
Point res; res.x = (c*t.b-t.c*b) / (a*t.b-t.a*b);
res.y = (c*t.a-t.c*a) / (b*t.a-t.b*a); return res;
}
int Mul(const Point &t)
{///用叉积判断方向
return Sign((E-S)^(t-S));
}
};
int CutPoly(Segment L, int N)
{
Point tmp[MAXN];
int cnt = ; for(int i=; i<=N; i++)
{
if(L.Mul(in[i]) <= )
tmp[++cnt] = in[i];
else
{
if(L.Mul(in[i-]) < )///求出交点
tmp[++cnt] = L.crossNode(Segment(in[i-],in[i]));
if(L.Mul(in[i+]) < )
tmp[++cnt] = L.crossNode(Segment(in[i],in[i+]));
}
} for(int i=; i<=cnt; i++)
in[i] = tmp[i];
in[] = in[cnt], in[cnt+] = in[]; return cnt;
} int main()
{
int T; scanf("%d", &T); while(T--)
{
int N, M;
double s=; scanf("%d", &N); for(int i=; i<=N; i++)
{
scanf("%lf%lf", &p[i].x, &p[i].y);
in[i] = p[i];
}
if(s < )
{
for(int i=; i<=N/; i++)
{
swap(p[i], p[N-i+]);
swap(in[i], in[N-i+]);
}
} in[] = p[] = p[N];
in[N+] = p[N+] = p[];
M = N; for(int i=; i<=N; i++)
M = CutPoly(Segment(p[i],p[i+]), M); for(int i=; i<=M; i++)
{
s += in[i].x*in[i+].y - in[i].y*in[i+].x;
} printf("%.2f\n", fabs(s)/2.0);
} return ;
}
Art Gallery - POJ 1279(求内核面积)的更多相关文章
- POJ 1279 Art Gallery 半平面交求多边形核
第一道半平面交,只会写N^2. 将每条边化作一个不等式,ax+by+c>0,所以要固定顺序,方便求解. 半平面交其实就是对一系列的不等式组进行求解可行解. 如果某点在直线右侧,说明那个点在区域内 ...
- poj 1279 Art Gallery - 求多边形核的面积
/* poj 1279 Art Gallery - 求多边形核的面积 */ #include<stdio.h> #include<math.h> #include <al ...
- POJ 1279 Art Gallery 半平面交/多边形求核
http://poj.org/problem?id=1279 顺时针给你一个多边形...求能看到所有点的面积...用半平面对所有边取交即可,模版题 这里的半平面交是O(n^2)的算法...比较逗比.. ...
- poj 1279 -- Art Gallery (半平面交)
鏈接:http://poj.org/problem?id=1279 Art Gallery Time Limit: 1000MS Memory Limit: 10000K Total Submis ...
- poj 1279 Art Gallery (Half Plane Intersection)
1279 -- Art Gallery 还是半平面交的问题,要求求出多边形中可以观察到多边形所有边的位置区域的面积.其实就是把每一条边看作有向直线然后套用半平面交.这题在输入的时候应该用多边形的有向面 ...
- poj 1279 半平面交核面积
Art Gallery Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 6668 Accepted: 2725 Descr ...
- 【POJ】【2068】Art Gallery
计算几何/半平面交 裸的半平面交,关于半平面交的入门请看神犇博客:http://blog.csdn.net/accry/article/details/6070621 然而代码我是抄的proverbs ...
- POJ 1151 / HDU 1542 Atlantis 线段树求矩形面积并
题意:给出矩形两对角点坐标,求矩形面积并. 解法:线段树+离散化. 每加入一个矩形,将两个y值加入yy数组以待离散化,将左边界cover值置为1,右边界置为2,离散后建立的线段树其实是以y值建的树,线 ...
- Area - POJ 1654(求多边形面积)
题目大意:从原点开始,1-4分别代表,向右下走,向右走,向右上走,向下走,5代表回到原点,6-9代表,向上走,向左下走,向左走,向左上走.求出最后的多边形面积. 分析:这个多边形面积很明显是不规则的, ...
随机推荐
- dvd的舞女
[题目描述] 众所周知,dvd是一个爱做梦的好孩子. 但是不知道为什么最近dvd总是梦到一群舞女 众所周知,dvd是一个爱琢磨的好孩子. 但是不知道为什么dvd最近一直想不明白为什么 终于dvd发现了 ...
- swfupload 上传控件的配置
第一:下载swfupload控件,点击下载: 第二,解压缩后,在项目中添加这四个文件,如图: 然后,在你的js文件中添加这段代码: /** * *定义swfupload配置文件对象 **/ var s ...
- tomcat 7 下添加 shared/lib 文件夹
你打开tomcat7\conf\catalina.properties文件再打开tomcat5的,看完后, 你就知道了 tomcat 5.5.35 # # List of comma-separate ...
- 虚拟机重复创建系统去除SID
我们安装完的操作系统都会有一个SID,为了简化安装,现在大部分人会选择GHOST克隆安装,经过克隆后的系统SID是相同的,有时需要重新获取SID 以前WIN2003有修改SID的工具NEWSID ...
- bzoj 3105: [cqoi2013]新Nim游戏 异或高消 && 拟阵
3105: [cqoi2013]新Nim游戏 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 535 Solved: 317[Submit][Stat ...
- 如何确定照片是否被PS过
除了用软件,还可以先右键属性----解除锁定----重新打开属性看详细信息.
- 使用div+css制作简单导航 以及要注意问题
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Android EditText的常用技巧
1. 设定 EditText 的滚动条.对齐方式.行数.和提示 (hint) 及其颜色 在布局文件,比如 main.xml 中,增加 < EditText android:id = ...
- 使用 jQuery.i18n.properties 实现 Web 前端的国际化
jQuery.i18n.properties 简介 在介绍 jQuery.i18n.properties 之前,我们先来看一下什么是国际化.国际化英文单词为:Internationalization, ...
- html5 鼠标跟随运动
<!DOCTYPE HTML> <html lang="en-US"> <head> <meta charset="UTF-8& ...