题目:Art Gallery

先求出内核,然后再求多边形的面积就行。

/*
Goujinping 2013.4.12  NEFU
The masterplate of Polygon kernel.
Now the global variable Area stand for the area of Polygon  kernel
In most case,the problem let us judge whether the Polygon kernel
exist or not and calculate the area,perimeter,or other constants
about the Polygon kernel.
*/
#include <math.h>
#include <stdio.h>
#include <iostream>
#include <algorithm>
using namespace std;
const int N=11111;
const double EPS = 1e-8;
typedef double DIY;
DIY Area,Length;
struct Point
{
DIY x,y;
Point() {}
Point(DIY _x,DIY _y):x(_x),y(_y) {}
} p[N];
Point MakeVector(Point &P,Point &Q)
{
return Point(Q.x-P.x,Q.y-P.y);
}
DIY CrossProduct(Point P,Point Q)
{
return P.x*Q.y-P.y*Q.x;
}
DIY MultiCross(Point P,Point Q,Point R)
{
return CrossProduct(MakeVector(Q,P),MakeVector(Q,R));
}
struct halfPlane
{
Point s,t;
DIY angle;
halfPlane() {}
halfPlane(Point _s,Point _t):s(_s),t(_t) {}
halfPlane(DIY sx,DIY sy,DIY tx,DIY ty):s(sx,sy),t(tx,ty) {}
void GetAngle()
{
angle=atan2(t.y-s.y,t.x-s.x);
}
} hp[N],q[N];
Point IntersectPoint(halfPlane P,halfPlane Q)
{
DIY a1=CrossProduct(MakeVector(P.s,Q.t),MakeVector(P.s,Q.s));
DIY a2=CrossProduct(MakeVector(P.t,Q.s),MakeVector(P.t,Q.t));
return Point((P.s.x*a2+P.t.x*a1)/(a2+a1),(P.s.y*a2+P.t.y*a1)/(a2+a1));
}
bool cmp(halfPlane P,halfPlane Q)
{
if(fabs(P.angle-Q.angle)<EPS)
return MultiCross(P.s,P.t,Q.s)>0;
return P.angle<Q.angle;
}
bool IsParallel(halfPlane P,halfPlane Q)
{
return fabs(CrossProduct(MakeVector(P.s,P.t),MakeVector(Q.s,Q.t)))<EPS;
}
void HalfPlaneIntersect(int n,int &m)
{
sort(hp,hp+n,cmp);
int i,l=0,r=1;
for(m=i=1; i<n; ++i)
if(hp[i].angle-hp[i-1].angle>EPS) hp[m++]=hp[i];
n=m; m=0;
q[0]=hp[0];q[1]=hp[1];
for(i=2; i<n; i++)
{
if(IsParallel(q[r],q[r-1])||IsParallel(q[l],q[l+1])) return;
while(l<r&&MultiCross(hp[i].s,hp[i].t,IntersectPoint(q[r],q[r-1]))>0) --r;
while(l<r&&MultiCross(hp[i].s,hp[i].t,IntersectPoint(q[l],q[l+1]))>0) ++l;
q[++r]=hp[i];
}
while(l<r&&MultiCross(q[l].s,q[l].t,IntersectPoint(q[r],q[r-1]))>0) --r;
while(l<r&&MultiCross(q[r].s,q[r].t,IntersectPoint(q[l],q[l+1]))>0) ++l;
q[++r]=q[l];
for(i=l; i<r; ++i)
p[m++]=IntersectPoint(q[i],q[i+1]);
}
void Solve(Point *p,int n,int &m)
{
int i,j;
Point a,b;
p[n]=p[0];
for(i=0;i<n;i++)
{
hp[i]=halfPlane(p[(i+1)%n],p[i]);
hp[i].GetAngle();
}
a=p[0],b=p[1];
HalfPlaneIntersect(n,m);
Area=0;
if(m>2)
{
p[m]=p[0];
for(i=0;i<m;++i)
Area+=CrossProduct(p[i],p[i+1]);
if(Area<0) Area=-Area;
}
Area/=2.0;
}
int main()
{
int n,m,t;
cin>>t;
while(t--)
{
cin>>n;
for(int i=0; i<n; i++)
cin>>p[i].x>>p[i].y;
Solve(p,n,m);
printf("%.2lf\n",Area);
}
return 0;
}

POJ1279(求多边形内核的面积)相关推荐

  1. ACM求多边形重心和面积问题

    描述 在某个多边形上,取n个点,这n个点顺序给出,按照给出顺序将相邻的点用直线连接, (第一个和最后一个连接),所有线段不和其他线段相交,但是可以重合,可得到一个多边形或一条线段或一个多边形和一个线段 ...

  2. 三角剖分求多边形面积的交 HDU3060

    1 //三角剖分求多边形面积的交 HDU3060 2 3 #include <iostream> 4 #include <cstdio> 5 #include <cstr ...

  3. 使用行列式公式求多边形面积

    namespace SKJZ {namespace lib{public struct Point { public float x, y;}public class Polygon{/// < ...

  4. 给定点坐标求多边形面积模板

    给定点坐标求多边形面积模板 方法:利用向量叉积求三角形面积的方法,把多边形分割成若干个三角形,然后求和得到多边形面积,计算时需要注意,给定的点的顺序必须是逆时针或者顺时针. 逆时针的方向是叉积的正方向 ...

  5. HDU 2036 改革春风吹满地(求多边形面积)

    转载请注明出处:http://blog.csdn.net/u012860063 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2036 改革春风吹满地 ...

  6. Java黑皮书课后题第8章:*8.33(几何:多边形的子面积)一个具有四个顶点的凸多边形被分为4个三角形,编写一个程序,提示用户输入4个顶点的坐标,然后以升序显示四个三角形的面积

    *8.33(几何:多边形的子面积)一个具有四个顶点的凸多边形被分为4个三角形,编写一个程序,提示用户输入4个顶点的坐标,然后以升序显示四个三角形的面积 题目 题目描述与运行示例 破题 代码 题目 题目 ...

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

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

  8. 求多边形的质心hdu1115

    给出点.然后求多边形的质心. 要求多边形的质心,就得先要知道三角形的质心要怎么求. 三角形的质心(A+B+C)/3. 可以用向量来证明. 然后我们还得知道质点系的质心公式:在质量均匀分布在质点上.如果 ...

  9. poj 1474 Video Surveillance - 求多边形有没有核

    /* poj 1474 Video Surveillance - 求多边形有没有核*/ #include <stdio.h> #include<math.h> const do ...

最新文章

  1. ArXiv 2020 | 抖音“变身漫画”滤镜背后的技术,难道来自这篇论文?
  2. jQuery源码分析系列
  3. git stash 个人理解
  4. ${oid?c}的使用
  5. React开发(117):ant design 新方式
  6. 三次握手的本质_关于TCP三次握手,这是我见过最好的解读了,通俗易懂
  7. oracle 创建,删除存储过程,参数传递,创建,删除存储函数,存储过程和函数的查看,包,系统包
  8. Linux下文件的权限管理及网络连接
  9. 计算机用户管理怎么进入,我有计算机管理员和受限用户不出现欢迎使用直接进入受限用户怎么办...
  10. 本土黑马谈车载语音识别 - 汽车电子 - 电子发烧友网
  11. 复制链接到safari浏览器打开_APP应用内嵌h5页面怎么直接打开Safari来访问链接?
  12. android中FileObserver的运用
  13. Broadcasting in Python
  14. 关于SAS学习的记录
  15. 永洪BI-实现按钮输出文件
  16. TortoiseGit 使用教程
  17. IOS 开发 手势使用
  18. sqlserver2008 服务 连接失败 -服务器名称如何写!!
  19. wxFormBuilder + wxPython 工具开发第四章-日记本工具文章内容增改删以及打包
  20. git:使用git cherry-pick命令

热门文章

  1. MapReduce-Combiner规约-原理分析
  2. v-if和v-show
  3. 数据库-优化-groupby的优化
  4. 数据库-查看数据库-创建数数据库
  5. 函数参数-函数参数的使用以及作用
  6. SpringBoot_数据访问-JDBC自动配置原理
  7. 字符之间或者结构体之间比较
  8. 【温故而知新-Javascript】使用 Ajax(续)
  9. tomcat配置文件详解
  10. 线上日志分析与其他一些脚本