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. ARX中类型强制转换

    比如 克隆 clone, 获得的是一个acrxobject, acrxobject *pobj=pployline->clone(); acdbpolyline *ppoly=acdbpolyl ...

  2. Django - 一对多跨表操作

    1.views.py 2.host.html 运行结果: 通过外键,来进行多表取值(多表取值包括后台取值及前端获取): 多表获取数据时,可以通过以下几种方式实现: 1.从query  set 中获取某 ...

  3. CF36E Two Paths (欧拉回路+构造)

    题面传送门 题目大意:给你一张可能有重边的不保证联通的无向图,现在要在这个图上找出两条路径,恰好能覆盖所有边一次,根据边的编号输出方案,无解输出-1 一道很不错的欧拉路径变形题 首先要知道关于欧拉路径 ...

  4. PAT 1109 Group Photo

    Formation is very important when taking a group photo. Given the rules of forming K rows with N peop ...

  5. java.lang.ClassFormatError: Unknown constant tag 0 in class file

    在通过文件上传之后,运行java程序,突然发现这么一个错误:java.lang.ClassFormatError: Unknown constant tag 0 in class file,通过网上查 ...

  6. [bzoj2648/2716]SJY摆棋子_KD-Tree

    SJY摆旗子 bzoj-2648 题目大意:平面上有n个黑子.有m个操作,可以下一颗白子,查询与曼哈顿距离下最近黑子之间的曼哈顿距离,或者下一颗黑子. 注释:$1\le n,m\le 5\cdot 1 ...

  7. Spring MVC-视图解析器(View Resolverr)-内部资源视图解析器(Internal Resource View Resolver)示例(转载实践)

    以下内容翻译自:https://www.tutorialspoint.com/springmvc/springmvc_internalresourceviewresolver.htm 说明:示例基于S ...

  8. hibernate分表保存日志

    @Service("accessLogService")@Transactionalpublic class LogMessageServiceImpl extends BaseD ...

  9. Codeforces Round #303 (Div. 2) E

    五道水题,但要手快才好...我手慢了,E题目都没看完TAT.... 想了一发,很水,就是一遍Dijk即可,使用优先队列,同时记录由哪条边转移而来 #include <iostream> # ...

  10. nginx access 日志位置

    nginx access 日志位置 /var/log/nginx tail -f access.log