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代表,向上走,向左下走,向左走,向左上走.求出最后的多边形面积. 分析:这个多边形面积很明显是不规则的, ...
随机推荐
- entity framework extended library , bulk execute,deleting and updating ,opensource
http://weblogs.asp.net/pwelter34/entity-framework-batch-update-and-future-queries
- BZOJ 3944 Sum 解题报告
我们考虑令: \[F_n = \sum_{d|n}\varphi(d)\] 那么,有: \[\sum_{i=1}^{n}F_i = \sum_{i=1}^{n}\sum_{d|i}\varphi(d) ...
- Linux(CentOS)常用命令
http://fedoranews.org/alex/tutorial/rpm/3.shtml rpm.org rpm -qa|grep mysql 查询已安装的含有mysql的包. mv 移动文件. ...
- POJ 3592 Instantaneous Transference(强联通分量 Tarjan)
http://poj.org/problem?id=3592 题意 :给你一个n*m的矩阵,每个位置上都有一个字符,如果是数字代表这个地方有该数量的金矿,如果是*代表这个地方有传送带并且没有金矿,可以 ...
- android 小米手机连接到电脑adb无法识别 解决方案
下载并安装小米手机助手 它会自动帮你安装驱动程序 安装成功后重启一下adb服务 应该就可以了
- leetcode面试准备: Game of Life
leetcode面试准备: Game of Life 1 题目 According to the Wikipedia's article: "The Game of Life, also k ...
- tbody添加垂直滚动条
法一: 用2个table: <table width="300" border="0" cellpadding="0" cellspa ...
- 11个强大的Visual Studio调试小技巧(转)
简介 调试是软件开发周期中很重要的一部分.它具有挑战性,同时也很让人疑惑和烦恼.总的来说,对于稍大一点的程序,调试是不可避免的.最近几年,调试工具的发展让很多调试任务变的越来越简单和省时. 这篇文章总 ...
- 【HDOJ】1260 Tickets
水DP,不过这道题目的数据好像有问题.24时制可表示范围是0~23,12时制可表示范围应为1~12.也就是说24点(即0点)其实表示为12:00:00am,而中午12:00:00其实表示为12:00: ...
- uiview scale
http://stackoverflow.com/questions/3946797/cgaffinetransformmakescale-makes-uiview-jump-to-original- ...