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. mysql幻读

    开启a,b两个数据库连接,a.b都开启事务后,b插入了一条数据R并提交,验证对a的操作造成的影响 select select for update update R update R 后 select ...

  2. Python 之动态添加属性以及方法

    import types class Person(object): def __init__(self, newName, newAge): self.name = newName self.age ...

  3. PAT_A1114#Family Property

    Source: PAT A1114 Family Property (25 分) Description: This time, you are supposed to help us collect ...

  4. Python 连接数据库 day5

    import pymysql #连接数据库,port必须是int型,字符编码是utf8,不能是utf-8,password必须是字符串 conn = pymysql.connect(host=', d ...

  5. 7-13 航空公司VIP客户查询 (25 分)

    题意: 思路: 读完题目之后的第一思路就是用map将客户的id(string类型)与里程road(int类型)形成映射,然后直接用id查找添加里程或输出里程.但是400ms的限制妥妥的超时了.然后意识 ...

  6. Java 初学者

    在有C++和C#基础之下开始学习Java,主要记录了一些和C++C#不同的或不知到的点 栈对象必须初始化,否则会报错.(其他的则有默认值) byte占用8位,char占用16位 接口默认为public ...

  7. Pyhon信息采集 - 喜马拉雅专辑歌曲

    目录 Pyhon信息采集 - 喜马拉雅专辑歌曲 Pyhon信息采集 - 喜马拉雅专辑歌曲 setting.py # 喜马拉雅URL XMLY_URL = "https://www.ximal ...

  8. Django——9 博客小案例的实现

    Django  博客小案例的实现 主要实现博客的增删改查功能 主页index.html  -->  展示添加博客和博客列表的文字,实现页面跳转 添加页add.html  --> 输入文章标 ...

  9. 【codeforces 796C】Bank Hacking(用一些技巧来代替multiset)

    [题目链接]:http://codeforces.com/contest/796/problem/C [题意] 给你n个节点,你一开始选择一个节点,然后打掉它,然后与被打掉过的节点相连的节点才能被 打 ...

  10. 【郑轻邀请赛 E】Can Win

    [题目链接]:https://acm.zzuli.edu.cn/zzuliacm/problem.php?id=2131 [题意] [题解] 尽量让自己喜欢的队赢; A内组内的比赛都让自己喜欢的队赢; ...