http://poj.org/problem?id=1584
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std; const int maxn=;
const double pi=acos(-1.0);
const double eps=10e-; int cmp(double x)
{
if(fabs(x)<eps) return ;
if(x>) return ;
return -;
} double sqr(double x)
{
return x*x;
} struct point
{
double x,y;
point(){}
point(double a,double b):x(a),y(b){}
bool operator <(const point &a)const
{
return (x<a.x)||(x==a.x&&y<a.y);
}
friend point operator -(const point &a,const point &b){
return point(a.x-b.x,a.y-b.y);
}
double norm(){
return sqrt(sqr(x)+sqr(y));
}
}p[maxn],ch[maxn]; struct line
{
point a,b;
line(){}
line(point x,point y):a(x),b(y){}
}; double det(point a,point b,point c)
{
return ((b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y));
} double cross(point a,point b,point c)
{
return ((b.x-a.x)*(c.y-b.y)-(c.x-b.x)*(b.y-a.y));
}
double det1(const point &a,const point &b)
{
return a.x*b.y-a.y*b.x;
} double dot(const point &a,const point &b)
{
return a.x*b.x+a.y*b.y;
} double dis(point a,point b)
{
return sqrt(sqr(a.x-b.x)+sqr(a.y-b.y));
} double dis_point_segment(const point p,const point s,const point t)
{
if(cmp(dot(p-s,t-s))<) return (p-s).norm();
if(cmp(dot(p-t,s-t))<) return (p-t).norm();
return fabs(det1(s-p,t-p)/dis(s,t));
} bool pointonsegment(point p,point s,point t)
{
return cmp(det1(p-s,t-s))==&&cmp(dot(p-s,p-t))<=;
} int convex_hull(point *p,int n,point *ch)
{
sort(p,p+n);
int m=;
for(int i=; i<n; i++)
{
while(m>&&det(ch[m-],ch[m-],p[i])<=) m--;
ch[m++]=p[i];
}
int k=m;
for(int i=n-; i>=; i--)
{
while(m>k&&det(ch[m-],ch[m-],p[i])<=) m--;
ch[m++]=p[i];
}
if(n>) m--;
return m;
} bool convex_hull1(point *p,int n)
{
int flag=;
p[n]=p[];
for(int i=; i<=n; i++)
{
//printf("%lf%lf %lf%lf %lf%lf\n",p[i-2].x,p[i-2].y,p[i-1].x,p[i-1].y,p[i].x,p[i].y);
int t=cmp(cross(p[i-],p[i-],p[i]));
//printf("%d\n",t);
if(!flag) flag=t;
if(flag*t<) return false;
}
return true;
}
int point_in(point t,point *ch,int n)
{
int num=,d1,d2,k;
ch[n]=ch[];
for(int i=; i<n; i++)
{
if(pointonsegment(t,ch[i],ch[i+])) return ;
k=cmp(det1(ch[i+]-ch[i],t-ch[i]));
d1=cmp(ch[i].y-t.y);
d2=cmp(ch[i+].y-t.y);
if(k>&&d1<=&&d2>) num++;
if(k<&&d2<=&&d1>) num--;
}
return num!=;
}
int main()
{
int n;
double r,x,y;
//freopen("sb.txt","w",stdout);
while(scanf("%d",&n)!=EOF)
{
if(n<) break;
scanf("%lf%lf%lf",&r,&x,&y);
point t(x,y);
for(int i=; i<n; i++)
{
scanf("%lf%lf",&p[i].x,&p[i].y);
} if(!convex_hull1(p,n))
{
printf("HOLE IS ILL-FORMED\n");
continue;
}
int cn=convex_hull(p,n,ch);
if(point_in(t,ch,cn))
{
double max1=dis_point_segment(t,ch[],ch[]);
for(int i=; i<cn+; i++)
{
max1=min(max1,dis_point_segment(t,ch[i-],ch[i]));
}
if(max1-r>=) printf("PEG WILL FIT\n");
else printf("PEG WILL NOT FIT\n");
}
else printf("PEG WILL NOT FIT\n");
}
return ;
}
poj A Round Peg in a Ground Hole的更多相关文章
-
POJ 1518 A Round Peg in a Ground Hole【计算几何=_=你值得一虐】
链接: http://poj.org/problem?id=1584 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...
-
POJ 1584 A Round Peg in a Ground Hole【计算几何=_=你值得一虐】
链接: http://poj.org/problem?id=1584 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...
-
POJ 1584 A Round Peg in a Ground Hole 判断凸多边形 点到线段距离 点在多边形内
首先判断是不是凸多边形 然后判断圆是否在凸多边形内 不知道给出的点是顺时针还是逆时针,所以用判断是否在多边形内的模板,不用是否在凸多边形内的模板 POJ 1584 A Round Peg in a G ...
-
A Round Peg in a Ground Hole(凸包应用POJ 1584)
A Round Peg in a Ground Hole Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5684 Accepte ...
-
POJ 1584 A Round Peg in a Ground Hole(判断凸多边形,点到线段距离,点在多边形内)
A Round Peg in a Ground Hole Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4438 Acc ...
-
POJ 1584 A Round Peg in a Ground Hole 判断凸多边形,判断点在凸多边形内
A Round Peg in a Ground Hole Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5456 Acc ...
-
POJ 1584 A Round Peg in a Ground Hole[判断凸包 点在多边形内]
A Round Peg in a Ground Hole Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 6682 Acc ...
-
POJ 1584:A Round Peg in a Ground Hole
A Round Peg in a Ground Hole Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5741 Acc ...
-
A Round Peg in a Ground Hole(判断是否是凸包,点是否在凸包内,圆与多边形的关系)
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4628 Accepted: 1434 Description The D ...
随机推荐
-
mako模板调试与使用技巧
django默认的模板太不灵活,想把一个数字0.15显示成15%都得费不少劲,太不爽!!! 网上查阅了几个模板系统,有Jinja2等等,最后发现mako能够直接支持python的语句,最为灵活,果断选 ...
-
/px/em/rem/的区别
PX特点: 1 .IE无法调整那些使用px作为单位的字体大小: 2. 国外的大部分网站能够调整的原因在于其使用了em或rem作为字体单位: 3.Firefox能够调整px和em,rem,但是96%以上 ...
-
HQ-SSAO (High-Quality SSAO)
踩了前前后后无数坑,实现方式都试过了10几种,终于得到这个方案.虽说比不上2015最新的far-field AO,但至少在near/middle-field上,算是state of arts的实现了. ...
-
安装多个版本的unity
版本特性导致新版本Unity打开老版本的项目工程报错,所以最好在电脑上安装多个不同版本的Unity 方法一 安装目录命名:Unity_3.5 , Unity_4.3.1 确保默认例子的安装路径分开C: ...
-
python的学习笔记01_4基础数据类型列表 元组 字典 集合 其他其他(for,enumerate,range)
列表 定义:[]内以逗号分隔,按照索引,存放各种数据类型,每个位置代表一个元素 特性: 1.可存放多个值 2.可修改指定索引位置对应的值,可变 3.按照从左到右的顺序定义列表元素,下标从0开始顺序访问 ...
-
【Dojo 1.x】笔记3 等待DOM加载完成
有的web页面总是得等DOM加载完成才能继续执行功能,例如,待页面DOM加载完成后,才能在DIV上进行渲染图形. Dojo提供了这个功能的模块,叫domReady,但是由于它很特殊,就在结尾加了个叹号 ...
-
ERP项目实施记录11-产品工艺流程图及单据关联图
借助百度的Echarts做了2个图表,一个展示产品的生产工艺流程,一个展示产品与订单.工程单的关系 上图为产品工艺流程图,鼠标放上去可以显示部件信息 黄色SO图标代表销售订单,单击打开销售订单 红色M ...
-
Linux解压缩命令tar
tar -c: 建立压缩档案-x:解压-t:查看内容-r:向压缩归档文件末尾追加文件-u:更新原压缩包中的文件 这五个是独立的命令,压缩解压都要用到其中一个,可以和别的命令连用但只能用其中一个.下面的 ...
-
webSphere-Eclipse中配置was的远程调试
目前我们项目中使用的应用服务器多是WebSphere,一直苦于无法进行调试,今天在网上看到一篇,原文是 http://www.cnblogs.com/newstar/archive/2010/04/1 ...
-
android开发资源
android仿微信 http://www.oschina.net/code/snippet_253900_33261