题目:How I Mathematician Wonder What You Are!

题意:给一个多边形,判断它是否是星形多边形,星形多边形的定义就是:如果在多边形内部能够找到一点能观察到多边形边上的所有点,那么此多边形就

           是星形多边形。

另外重要的一点就是本题点的输入方向是逆时针方向。所以先变为顺时针。

/*
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;
p[n]=p[0];
for(i=0;i<n;i++)
{
hp[i]=halfPlane(p[(i+1)%n],p[i]);
hp[i].GetAngle();
}
HalfPlaneIntersect(n,m);
}
int main()
{
int n,m;
Point temp[N];
while(cin>>n)
{
if(n==0) break;
for(int i=0; i<n; i++)
{
cin>>temp[i].x>>temp[i].y;
p[n-i-1]=temp[i];
}
Solve(p,n,m);
if(m<3)  puts("0");
else     puts("1");
}
return 0;
}

POJ3130(还是判断多边形的内核是否存在)相关推荐

  1. POJ3335(判断多边形内核是否存在)

    题目:Rotating Scoreboard 题意:题目要求判断多边形内核是否存在,若存在就输出YES,不存在就输出NO,本题和POJ1474一样.本题点的输入顺序是顺时针方向. /* Goujinp ...

  2. 面积法判断多边形顺逆时针

    面积法判断多边形顺逆时针 // 输入:按照顺序输入多边形的轮廓顶点 // 输出:0代表数据有问题,-1代表逆时针,1代表顺时针 int estimateContourType(std::vector& ...

  3. js判断多边形的坐标点是顺时针还是逆时针的两种方法

    js判断多边形的坐标点是顺时针还是逆时针的两种方法 关键算法 通过极值点与其相邻点的构成的矢量走向算出多边形走向 通过计算各左边点所在矢量夹角的角度总和来推算多边形走向 由于arcgis对顺时针生成的 ...

  4. python 判断多边形,点是否重合(方法简单易懂,没有使用 cv2.pointPolygonTest函数)

    python 判断多边形,点是否重合 首先代码并未使用 cv2.pointPolygonTest 这一opencv函数,因为自己在使用时,一直报错,很难自己构造出适用于 pointPolygonTes ...

  5. android浏览器内核检测,一段非常简单的js判断浏览器的内核

    大家应该还记得JavaScript行内样式怎么写吧?(看来我是废话了!) 在前端开发过程中,有时我们需要判断浏览器的内核前缀,对不同的浏览器做出不同的处理,因此我们可以这么做. alert(eleme ...

  6. html检测浏览器内核,判断浏览器的内核及版本号方法汇总_jquery

    通过jquery 判断浏览器的内核及版本号 通过浏览器版本信息判断各浏览器 var _uat=navigator.userAgent; if(_uat.indexOf("MSIE 6.0&q ...

  7. 判断多边形的凹凸性和计算多边形面积:利用向量叉乘

    根据百度百科的讲解: 凸多边形 现在重点讲解顶点凹凸性法(最常用也是较为简单的方法):计算总结在最后. 利用向量叉乘的相关知识进行计算:假设当前连续的三个顶点分别是P1,P2,P3.计算向量P1P3, ...

  8. php判断浏览器内核,jquery如何判断浏览器的内核

    jquery判断浏览器内核的方法:使用条件语句判断,代码为[$(function(){if($.browser.msie) {alert("IE浏览器");}else if($.b ...

  9. zoj 1010 (线段相交判断+多边形求面积)

    链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=10 Area Time Limit: 2 Seconds      Mem ...

最新文章

  1. Pangolin在cmake时报“Could NOT find GLEW”错误
  2. 天翼云从业认证(1.1)服务器的分类、用途、特点、结构和组件
  3. python 在列表中完成队列的删除和排序
  4. 远控免杀专题(16)-Unicorn免杀
  5. 版本低于1.7的jQuery过滤用户输入数据所使用的正则表达式存在缺陷
  6. activiti jbpm相关资源
  7. 信息学奥赛一本通 1048:有一门课不及格的学生 | OpenJudge NOI 1.4 10
  8. 营收放缓、股价暴跌、高管离职,Facebook迎来至暗时刻?
  9. [转]Cuda笔记【1】GPU计算DEMO
  10. Flutter基础—绘画效果之装饰容器
  11. Linux设备驱动中的异步通知
  12. centos7安装中文字体
  13. 自动化报表,标准化流程---“JSL”(JMP编程语言),与重复操作说拜拜
  14. 大数据Spark(五十二):Structured Streaming 事件时间窗口分析
  15. Modelica运算符
  16. 合同法律风险管理 被骗者刑事风险
  17. Kienct与Arduino学习笔记(1) 基础知识之Arduino’Kinect‘Processing
  18. 电脑pc页面在手机缩放显示
  19. 虚拟机VM利用U盘重装系统
  20. 多处理器下的中断机制

热门文章

  1. Spring 核心容器类BeanDefinition
  2. 仓库的种类和彼此关系
  3. 用户操作-用户添加操作代码实现
  4. springioc注解版运行效果演示
  5. Redis与Lua详解
  6. 方法重写(override)注意事项和使用细节
  7. php flash chart,openflashchart 2.0 简单案例php版
  8. nginx配置文件详细解读
  9. oracle 11g goldengate与oracle 11g数据同步
  10. 参加51CTO组织的2013云计算架构师大会