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 ... 
随机推荐
- php动态分页类
			<?php /** * 页面名称:cls_page.php */ class Page { private $each_disNums; //每页显示的条目数 private $nums; // ... 
- 30余套系统模版|DIV+CSS网页模板|简洁大气系统模板
			30余套系统模版|DIV+CSS网页模板|简洁大气系统模板.都是一些后台系统的模版,很适合开发一些管理系统,办公系统,网站后台系统等.使用很广泛,很实用的系统模版. 下载地址: 点击下载 
- OS开发 touch事件的优先级和事件传递
			界面类的对象一般都是可以接触点击事件的,只不过有的默认接受,有的需要设定属性. userInteractionEnabled 属性设置为YES的时候就可以接受点击事件了 - (void)touches ... 
- android——wifi系统架构
			1. 系统架构 Android WiFi系统引入了wpa_supplicant,它的整个WiFi系统以wpa_supplicant为核心来定义上层用户接口和下层驱动接口.整个WiFi系统架构如下图所示 ... 
- 设置IIS7文件上传的最大大小 maxAllowedContentLength,maxRequestLength
			当上传一个超过30M的文件时,服务器会重定向至404.13页面,报错如下: HTTP Error 404.13 - Not Found The request filtering module is ... 
- DM8168 坎坷硬件之路(DDR3)
			新做了8168板,调试DDR3的时候EMIF0遇到了个别数据位出错的问题 DDR3 128MB*8=1GB 我为了測试DDR3的所有空间,把地址存到DDR3中,就是*pdata++=(Uint32)p ... 
- RT: TCP connection close
			CLOSE is an operation meaning "I have no more data to send." The notion of closing a full- ... 
- 简单说明Python中的装饰器的用法
			简单说明Python中的装饰器的用法 这篇文章主要简单说明了Python中的装饰器的用法,装饰器在Python的进阶学习中非常重要,示例代码基于Python2.x,需要的朋友可以参考下 装饰器对与 ... 
- 【开源java游戏框架libgdx专题】-14-系统控件-Skin类
			Skin类主要用于存储用户界面的资源,该资源主要用于窗口部件.这些资源也包括纹理图片.位图画笔.颜色等内容.方便创建游戏组件,同时使用Skin也可以批量的粗略处理一些窗口部件. test.json { ... 
- (转)PHP函数set_magic_quotes_runtime()的作用
			新手经常遇到的问题是特殊字符提交的时候提示数据库错误,今天给大家介绍一个set_magic_quotes_runtime函数,来帮助我们过滤里面的内容 php函数 set_magic_quotes_r ... 
