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 ...
随机推荐
- 实验2 C++数组与指针
一.实验目的: 掌握一维数组和二维数组的定义.赋值和输入输出的方法. 掌握字符数组和字符串函数的使用. 通过实验进一步掌握指针的概念,会定义和使用指针变量. 能正确使用数组的指针和指向数组的指针变量. ...
- Zabbix 监控磁盘IO
Zabbix 监控磁盘IO 1.数据获取脚本 #!/bin/bash # resource: http://www.muck.net/19/getting-hard-disk-performance- ...
- struts.xml详解
参考自:http://blog.csdn.net/zz_mm/article/details/5460397 1. 深入Struts2的配置文件 本部分主要介绍struts.xml的常用配置. ...
- linux安装mysql可视化工具MySQL-workbench 连接数据库 执行sql
Step1:建立数据库连接 点击新建连接的按钮,符号是“+”的按钮,出现下图,在“Connection name”输入连接名称. 填写连接信息 输入数据库连接密码 测试连接: 再次点击连接时会要求输入 ...
- table案例一
实现效果: html <style> #mform{ margin: 10px; } #mtable{ border-collapse: collapse; } #mtable thead ...
- Django - 内容总结(1)
内容整理: 1.创建django工程名称 django-admin startproject 工程名 2.创建app cd 工程名 python manage.py startapp cmdb 3.静 ...
- EF 配置
DbContext public class ZSZDbContext : DbContext { //ILog ILogger 容易混淆 private static ILog log = LogM ...
- 15.6.2【Task使用】 组合异步操作
对于C# 5异步特性,我最喜欢的一点是它可以自然而然地组合在一起.这表现为两种不同的 方式.最明显的是,异步方法返回任务,并通常会调用其他返回任务的方法.这些方法可以是直 接的异步操作(如链的最底部) ...
- sysbench_memory
对于内存而言,这里--memory-total-size=100G 就是 意味着 total number of events: 104857600 1. --memory-total-size=10 ...
- Spring框架学习之SpringAOP(二)
AOP概念 AOP(Aspect-Oriented Programming,面向切面编程),AOP是OOP(面向对象编程)的补充和完善 AOP的核心思想就是“将应用程序中的商业逻辑同对其提供支持的通用 ...