A Round Peg in a Ground Hole(圆与凸包)
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(圆与凸包)的更多相关文章
- 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: 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 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
A Round Peg in a Ground Hole Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5741 Acc ...
- POJ 1584 A Round Peg in a Ground Hole 判断凸多边形 点到线段距离 点在多边形内
首先判断是不是凸多边形 然后判断圆是否在凸多边形内 不知道给出的点是顺时针还是逆时针,所以用判断是否在多边形内的模板,不用是否在凸多边形内的模板 POJ 1584 A Round Peg in a G ...
- 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 ...
- A Round Peg in a Ground Hole(判断是否是凸包,点是否在凸包内,圆与多边形的关系)
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4628 Accepted: 1434 Description The D ...
随机推荐
- Java编译器、JVM、解释器
Java虚拟机(JVM)是可运行Java代码的假想计算机.只要根据JVM规格描述将解释器移植到特定的计算机上,就能保证经过编译的任何Java代码能够在该系统上运行.本文首先简要介绍从Java文件的编译 ...
- 关于Python中的类普通继承与super函数继承
关于Python中的类普通继承与super函数继承 1.super只能用于新式类 2.多重继承super可以保公共父类仅被执行一次 一.首先看下普通继承的写法 二.再看看super继承的写法 参考链接 ...
- (转)OGNL与值栈
http://blog.csdn.net/yerenyuan_pku/article/details/67709693 OGNL的概述 什么是OGNL 据度娘所说: OGNL是Object-Graph ...
- 在把table表格中的数据导出到Excel的时候,以科学计数法显示位数多的数字时怎么解决?
sbHtml.AppendFormat("<td> {0}</td>", data[i].IDcard.ToString()); sbHtml.Append ...
- unittest 是什么?怎么用?
unittest单元测试框架详解 https://www.cnblogs.com/fighter007/p/8245063.html unittest最详细的解说 https://www.cnblog ...
- Windows如何正确的修改administrator用户名
无论是服务器还是电脑.修改默认的administrator的用户总是好的.话不多少.直接上图 1.win+r 输入:gpedit.msc 2.按照我下图的圈圈找到重命名系统管理员账户并自定义 3.重 ...
- js基本类型的包装对象
var test = "test"; test.a = "hello"; console.log(test.a); 在JavaScript中,“一切皆对象”,数 ...
- 小白年薪24万,为什么Linux运维工程师薪资这么高?
借了云计算的东风,Linux岗位这几年是越来越火,特别是Linux云计算运维工程师,如今早已成为互联网的核心岗位之一,薪资待遇飞快的上涨. 作为一个细分的专业岗位,Linux云计算工程师由于其入门学习 ...
- JavaScript day3(数据类型)
数据类型(data type) JavaScript提供七种不同的数据类型(data types),它们是string(字符串), symbol(符号), number(数字), undefined( ...
- 洛谷——P2342 叠积木
P2342 叠积木 题目大意: 给你一堆积木,排成一行,初始时每对积木都只有一个,支持两种操作 第一种是移动操作,格式为“移动X到Y的上面”.X和Y代表两块积木的编号,意思是将X所的那堆积 ...