http://poj.org/problem?id=1584

题意:判断所给的点能不能形成凸包,并判断所给的圆是否在凸包内。

改了好几天的一个题,今天才发现是输入顺序弄错了,办过的最脑残的事情。。sad

 #include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string.h>
#include <math.h>
using namespace std;
const int N=;
const double eps=1e-;
double pi=acos(-1.0);
int n;
struct point
{
double x,y;
point(double x = ,double y = ):x(x),y(y) {}
double norm()//向量的模
{
return sqrt(x*x+y*y);
} };
point operator-(const point &a,const point &b)
{
return point(a.x-b.x,a.y-b.y);
}
int cmp(double x)//精度处理
{
if (fabs(x) < eps)
return ;
if (x > )
return ;
return -; }
double det(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 dist(const point &a,const point &b)//两点间的距离
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
bool PointOnSegment(point p,point s,point t)//判断点是否在线段上
{
return cmp(det(p-s,t-s))==&&cmp(dot(p-s,p-t))<=;
} 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(det(s-p,t-p)/dist(s,t));
}
bool is_convex(point *p)//判断凸包
{
int pre = ;
p[n] = p[];
p[n+] = p[];
for (int i = ; i <= n; i++)
{
int dir = cmp(det(p[i-]-p[i-],p[i]-p[i-]));
if (!pre)
pre = dir;
if (pre*dir < ) return false;
}
return true;
}
int point_in(point t,point *ch)//判断点是否在凸包内
{
int num=,d1,d2,k;
ch[n]=ch[];
for(int i=; i<n; i++)
{
if(PointOnSegment(t,ch[i],ch[i+])) return ;
k=cmp(det(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()
{
double x,y,r;
while(~scanf("%d",&n))
{
if (n < )
break;
point p[N];
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);
}
p[n] = p[];//连接首尾的点
if (!is_convex(p))
{
printf("HOLE IS ILL-FORMED\n");
continue;
}
if(point_in(t,p))
{
double Min = dis_point_segment(t,p[],p[]);
for (int i = ; i < n; i++)
{
double dis = dis_point_segment(t,p[i],p[i+]);
Min = min(dis,Min);//圆心到所有线段的最小距离
}
if (cmp(Min-r)>= )
printf("PEG WILL FIT\n");
else
printf("PEG WILL NOT FIT\n");
}
else
printf("PEG WILL NOT FIT\n"); }
return ;
}

A Round Peg in a Ground Hole(圆与凸包)的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. POJ 1584 A Round Peg in a Ground Hole 判断凸多边形 点到线段距离 点在多边形内

    首先判断是不是凸多边形 然后判断圆是否在凸多边形内 不知道给出的点是顺时针还是逆时针,所以用判断是否在多边形内的模板,不用是否在凸多边形内的模板 POJ 1584 A Round Peg in a G ...

  8. 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 ...

  9. A Round Peg in a Ground Hole(判断是否是凸包,点是否在凸包内,圆与多边形的关系)

    Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4628   Accepted: 1434 Description The D ...

随机推荐

  1. 最适合初学者的Linux运维学习教程2018版

    Linux运维工程师是一个新颖岗位,现在非常吃香,目前从行业的角度分析,随着国内软件行业不断发展壮大,越来越多复杂系统应运而生,为了保证系统稳定运行,必须要有足够多的Linux运维工程师.维护是软件生 ...

  2. 《啊哈算法》中P81解救小哈

    题目描述 首先我们用一个二维数组来存储这个迷宫,刚开始的时候,小哼处于迷宫的入口处(1,1),小哈在(p,q).其实这道题的的本质就在于找从(1,1)到(p,q)的最短路径. 此时摆在小哼面前的路有两 ...

  3. scrapy实例matplotlib脚本下载

    利用scrapy框架实现matplotlib实例脚本批量下载至本地并进行文件夹分类:话不多说上代码: 首先是爬虫代码: import scrapy from scrapy.linkextractors ...

  4. SGC强制最低128位加密,公钥支持ECC加密算法的SSL证书

      Pro SSL证书,验证企业域名所有权和企业身份信息,采用SGC(服务器门控)技术强制128位以上至256位加密,属于企业OV验证级专业版(Pro) SSL证书:即使用户使用低版本浏览器(比如浏览 ...

  5. eclipse 下使用 git

    一.默认仓库文件夹 二.window -->perspective --> customize perspective 三.提交时,要忽略的文件

  6. 常用Git命令大全思维导图

    开发中代码管理少不了使用Git,对于初学者来说Git命令的学习是一个难过的坎,为了帮助大家记忆并快速掌握Git的基本使用,我把常用的Git命令整理成思维导图,分享给大家. 高清大图在线预览 http: ...

  7. PL/SQL Challenge 每日一题:2014-3-14 11gR2中带RELIES_ON子句的RESULT_CACHE函数

    PL/SQL Challenge 每日一题:2014-3-14 11gR2中带RELIES_ON子句的RESULT_CACHE函数 最先答对且答案未经编辑的puber将获得纪念章一枚(答案不可编辑但可 ...

  8. P - How many

    Give you n ( n < 10000) necklaces ,the length of necklace will not large than 100,tell me How man ...

  9. [bzoj3747][POI2015]Kinoman_线段树

    Kinoman bzoj-3747 POI-2015 题目大意:有m部电影,第i部电影的好看值为w[i].现在放了n天电影,请你选择一段区间l~r使得l到r之间的好看值总和最大.特别地,如果同一种电影 ...

  10. spring入门笔记

    这是我自己学习韩顺平老师spring视频的笔记,个人认为初学spring的韩顺平老师的讲的很好,比较通俗易懂,资源地址我已经给了,可以自己配合视频看.主要介绍了ioc和aop,这也是spring框架最 ...