poj A Round Peg in a Ground Hole
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 ...
随机推荐
- iframe页面改动parent页面的隐藏input部件value值,不能触发change事件。
实现一个依据iframe页面返回充值卡类型不同,安排不同的input部件. 点击选择弹出一个iframe.点击充值卡数据行.返回1.充值卡类型.2.充值卡id(用的UUID).3.充值卡号(字符串). ...
- Java 8 Features – The ULTIMATE Guide--reference
Now, it is time to gather all the major Java 8 features under one reference post for your reading pl ...
- linux之CentOS-7.0环境搭建
此文作为新手安装centos-7的图文教程. 一. 前言 最近,师兄要进行实验室架构搭建,需要学习docker.而docker是完全依赖于linux系统的.所以,有了这篇文章. linux有很多发 ...
- codevs 3305 水果姐逛水果街Ⅱ
/*我尼玛 又一个min打成max 看了半天....*/ #include<iostream> #include<cstdio> #include<cstring> ...
- css 圆角效果
http://intacto10years.com/index_start.php<div style="width:800px; height:1300px;">&l ...
- maven update 以后报错。
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start com ...
- iOS开发知识点:理解assign,copy,retain变strong
一..h和.m文件的变化说明 1.对于.h头文件,主要是将属性定义由retain变为strong @property (retain, nonatomic) 变为 @property (strong, ...
- <address>标签,为网页加入地址信息
一般网页中会有一些网站的联系地址信息需要在网页中展示出来,这些联系地址信息如公司的地址就可以<address>标签.也可以定义一个地址(比如电子邮件地址).签名或者文档的作者身份. 语法: ...
- MySQL被Oracle并购后的409个日日夜夜
2009年4月20日,Oracle并购了Sun,这也意味着MySQL归属到甲骨文的旗下.四百多天过去了,究竟这场并购结局如何?请看本文. 去年对Sun的收购,让甲骨文顺利的将一个潜在的对手MySQL收 ...
- 『重构--改善既有代码的设计』读书笔记----Replace Temp with Query
Replace Temp with Query,顾名思义,表示你用查询来替换临时变量本身,临时变量对于函数来说是只有当前函数可见的,如果你在同类的别的地方要用到这个变量你就必须重新写表达式来获取这个变 ...