poj1584A Round Peg in a Ground Hole
题意甚是难懂!这是第二遍做这道题了,依旧无法理解题意,搜了下题意。。。
首先需要判断是不是为凸多边形。(从一个顶点走一遍即可,要注意顺逆时针,题目中没有指明)
其次看一下圆是不是能够放入多边形内。(首先判断一下圆心是否在圆内,然后枚举圆心到所有边的距离与半径r进行比较)
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define N 10000
#define LL long long
#define INF 0xfffffff
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
#define _sign(x) ((x) > eps?1:((x) < -eps ? 2 :0))
struct Point
{
double x,y;
Point(double x=,double y=):x(x),y(y) {}
}p[N],ch[N];
int top;
struct Circle
{
Point c;
double r;
//Circle(Point c,double r):c(c),r(r){}
Point point (double a)
{
return Point(c.x+cos(a)*r,c.y+sin(a)*r);
}
};
typedef Point pointt;
pointt operator + (Point a,Point b)
{
return Point(a.x+b.x,a.y+b.y);
}
pointt operator - (Point a,Point b)
{
return Point(a.x-b.x,a.y-b.y);
}
double cross(Point a,Point b)
{
return a.x*b.y-a.y*b.x;
}
double mul(Point p0,Point p1,Point p2)
{
return cross(p1-p0,p2-p0);
}
double dis(Point a)
{
return sqrt(a.x*a.x+a.y*a.y);
}
//精度判正负
int dcmp(double x)
{
if(fabs(x)<eps) return ;
else return x<?-:;
}
int Graham(int n)
{
int i,s[] = {,,};
double t;
for(i = ; i < n&&s[]|s[]; i ++)
{
t = mul(p[(i+)%n],p[(i+)%n],p[i]);
s[_sign(t)] = ;
}
return s[]|s[];
}
double distoline(Point p,Point a,Point b)
{
Point v1 = b-a,v2 = p-a;
return fabs(cross(v1,v2)/dis(v1));
}
int inside(Point po,int n)
{
int i,s[] = {,,};
double t;
for(i = ;i < n&&s[]|s[];i ++)
{
t = mul(p[(i+)%n],po,p[i]);
s[_sign(t)] = ;
}
return s[]|s[];
}
int main()
{
int n,i;
Circle cc;
while(scanf("%d",&n)!=EOF)
{
if(n<) break;
scanf("%lf%lf%lf",&cc.r,&cc.c.x,&cc.c.y);
for(i = ; i < n; i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
top = ;
int m = Graham(n);
if(!m)
{
puts("HOLE IS ILL-FORMED");
continue;
}
int flag = ;
if(!inside(cc.c,n))
{
puts("PEG WILL NOT FIT");
continue;
}
for(i = ; i < n; i ++)
{
if(dcmp(distoline(cc.c,p[i],p[i-])-cc.r)<)
{
flag = ;
break;
}
}
if(!flag)
puts("PEG WILL NOT FIT");
else
puts("PEG WILL FIT");
}
return ;
}
poj1584A 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: 4438 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: 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 ...
- A Round Peg in a Ground Hole(判断是否是凸包,点是否在凸包内,圆与多边形的关系)
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4628 Accepted: 1434 Description The D ...
随机推荐
- 常用的math函数
<?php //1.abs — 绝对值 echo abs(-77); //ceil — 进一法取整 ...
- PullToRefresh 下拉刷新的样式修改
资源文件结构图, 先看看下拉刷新头的布局, <?xml version="1.0" encoding="utf-8"?> <merge xml ...
- ACM题目————STL练习之字符串替换
描述 编写一个程序实现将字符串中的所有"you"替换成"we" 输入 输入包含多行数据 每行数据是一个字符串,长度不超过1000 数据以EOF结束 输出 对于输 ...
- Pearls
Pearls Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7980 Accepted: 3966 Description In ...
- Poj(1273),最大流,EK
Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 69355 Accepted: 2687 ...
- 准确率(Precision)、召回率(Recall)以及F值(F-Measure)
转载自:http://blog.csdn.net/yechaodechuntian/article/details/37394967 https://www.zhihu.com/question/19 ...
- tomcat异常: Cannot get a connection, pool exhausted
1 问题描述Web程序在tomcat刚开始运行时速度很快,但过一段时间后发现速度变得很慢. 检查日志输出,发现异常如下:org.apache.commons.dbcp.SQLNestedExcepti ...
- key可以重复的Map集合:IdentityHashMap
所有Map操作中key的值是不能重复的,例如,HashMap操作时key是不能重复的,如果重复则肯定会覆盖之前的内容,如下代码所示. 范例:Map中的key不允许重复,重复就是覆盖 package o ...
- Java -Dfile.encoding=UTF-8 出现乱码问题原因分析
这两天写了一个 Java 程序来玩,结果又遭遇了以前遇到过很多次的乱码问题,具体描述一下: 在 Mac 系统里面,常用的 Java 程序启动方式有如下几种: 1.通过 eclipse 执行 class ...
- 4-JS对象
js中哪些是对象 除了字符串.数字.false.true.null和undefined之外,JavaScript中的值都是对象 原型(prototype) 每一个JavaScript对象(null除外 ...