链接:




A Round Peg in a Ground Hole
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 4475   Accepted: 1374

Description

The DIY Furniture company specializes in assemble-it-yourself furniture kits. Typically, the pieces of wood are attached to one another using a wooden peg that fits into pre-cut holes in each piece to be attached. The pegs have a circular cross-section and
so are intended to fit inside a round hole. 

A recent factory run of computer desks were flawed when an automatic grinding machine was mis-programmed. The result is an irregularly shaped hole in one piece that, instead of the expected circular shape, is actually an irregular polygon. You need to figure
out whether the desks need to be scrapped or if they can be salvaged by filling a part of the hole with a mixture of wood shavings and glue. 

There are two concerns. First, if the hole contains any protrusions (i.e., if there exist any two interior points in the hole that, if connected by a line segment, that segment would cross one or more edges of the hole), then the filled-in-hole would not be
structurally sound enough to support the peg under normal stress as the furniture is used. Second, assuming the hole is appropriately shaped, it must be big enough to allow insertion of the peg. Since the hole in this piece of wood must match up with a corresponding
hole in other pieces, the precise location where the peg must fit is known. 

Write a program to accept descriptions of pegs and polygonal holes and determine if the hole is ill-formed and, if not, whether the peg will fit at the desired location. Each hole is described as a polygon with vertices (x1, y1), (x2, y2), . . . , (xn, yn).
The edges of the polygon are (xi, yi) to (xi+1, yi+1) for i = 1 . . . n − 1 and (xn, yn) to (x1, y1).

Input

Input consists of a series of piece descriptions. Each piece description consists of the following data: 

Line 1 < nVertices > < pegRadius > < pegX > < pegY > 

number of vertices in polygon, n (integer) 

radius of peg (real) 

X and Y position of peg (real) 

n Lines < vertexX > < vertexY > 

On a line for each vertex, listed in order, the X and Y position of vertex The end of input is indicated by a number of polygon vertices less than 3.

Output

For each piece description, print a single line containing the string: 

HOLE IS ILL-FORMED if the hole contains protrusions 

PEG WILL FIT if the hole contains no protrusions and the peg fits in the hole at the indicated position 

PEG WILL NOT FIT if the hole contains no protrusions but the peg will not fit in the hole at the indicated position

Sample Input

5 1.5 1.5 2.0
1.0 1.0
2.0 2.0
1.75 2.0
1.0 3.0
0.0 2.0
5 1.5 1.5 2.0
1.0 1.0
2.0 2.0
1.75 2.5
1.0 3.0
0.0 2.0
1

Sample Output

HOLE IS ILL-FORMED
PEG WILL NOT FIT

Source



题意:


给你一个含有 N个点的多边形和一个钉子

        判断钉子是否在多边形内部


注意:

输入的第一行先输入多边形的点数,   

再输入的是钉子的半径,然后才是坐标ToT

思路:


1.先判断多边形是不是凸多边形,

           如果不是,则输出 HOLE IS ILL-FORMED

          如果是,则继续往下判断

       2.(1)判断圆心是否在凸多边形外面

            如果在外面,直接返回 false

            如果在边上,而且半径 == 0,返回 true

                       半径不为 0 , 返回 false

            如果在内部,则遍历圆心到每一条边线段的距离是否 >= 半径

                       如果全部满足,则返回 true

                       否则返回 false

         如果钉子能装下,则输出PEG WILL FIT

         否则输出PEG WILL NOT FIT


忠告:不要NC


相关测试题目:




开始一直WA直到找了这三道基础的题目AC完



/***************************************************
Accepted 192 KB 0 ms C++ 4208 B 2013-07-28 16:02:24
题意:给你一个含有 N个点的多边形和一个钉子
判断钉子是否在多边形内部
注意:输入的第一行先输入多边形的点数,
再输入的是钉子的半径,然后才是坐标ToT 思路:1.先判断多边形是不是凸多边形,
如果不是,则输出 HOLE IS ILL-FORMED
如果是,则继续往下判断
2.(1)判断圆心是否在凸多边形外面
如果在外面,直接返回 false
如果在边上,而且半径 == 0,返回 true
半径不为 0 , 返回 false
如果在内部,则遍历圆心到每一条边线段的距离是否 >= 半径
如果全部满足,则返回 true
否则返回 false
如果钉子能装下,则输出PEG WILL FIT
否则输出PEG WILL NOT FIT
***************************************************/
#include<stdio.h>
#include<math.h> const int maxn = 200; struct Point{
double x,y; Point() {}
Point(double _x, double _y) {
x = _x;
y = _y;
}
Point operator - (const Point &B)
{
return Point(x-B.x, y-B.y);
}
}p[maxn]; struct Circle{
Point center;
double radius;
}c; const double eps = 1e-5;
int dcmp(double x)
{
if(fabs(x) < 0) return 0;
else return x < 0 ? -1 : 1;
} bool operator == (const Point &A, const Point &B)
{
return dcmp(A.x-B.x)== 0 && dcmp(A.y-B.y) == 0;
} double Cross(Point A, Point B) /** 叉积*/
{
return A.x*B.y - A.y*B.x;
}
double Dot(Point A, Point B) /** 点积*/
{
return A.x*B.x+A.y*B.y;
} double Length(Point A)
{
return sqrt(A.x*A.x + A.y*A.y);
} /** 判断多边形是否是凸多边形【含共线】*/
bool isConvex(Point *p, int n)
{
p[n] = p[0]; // 边界处理
p[n+1] = p[1]; // 注意也可以用 %n 处理, 下标从 0 开始
int now = dcmp(Cross(p[1]-p[0], p[2]-p[1]));
for(int i = 1; i < n; i++)
{
int next = dcmp(Cross(p[i+1]-p[i], p[i+2]-p[i+1]));
if(now*next < 0) //此处可以共线
{
return false;
}
now = next; //注意记录临界条件
}
return true;
} /** 点Point 是否在有 n 个顶点的凸多边形内【含边界】*/
int isPointInConvex(Point *p, int n, Point point)
{
int flag = 1;
p[n] = p[0];
int now = dcmp(Cross(p[0]-point, p[1]-point));
for(int i = 1; i < n; i++)
{
int next = dcmp(Cross(p[i]-point, p[i+1]-point));
if(next*now < 0)
{
return -1; /** 点在外面*/
}
else if(next*now == 0)
{
return 0; /** 点在边上 */
}
now = next;
}
return flag; /** 点在内部*/
} /** 判断点P 到线段 AB的距离*/
double DistanceToSegment(Point P, Point A, Point B)
{
if(A == B) return Length(P-A);
Point v1 = B-A;
Point v2 = P-A;
Point v3 = P-B; if(dcmp(Dot(v1, v2)) < 0) return Length(v2);
else if(dcmp(Dot(v1, v3)) > 0) return Length(v3);
else return fabs(Cross(v1, v2))/ Length(v1); //忠告:不要脑残的 / 2...
} /** 判断圆是否在凸多边形内部, 相切也可以*/
bool isCircleInConvex(Point *p, int n, Circle c)
{
int flag = isPointInConvex(p, n, c.center); /**判断圆心*/ if(flag == 0) /** 圆心在边上*/
{
if(c.radius == 0) return true;
else return false;
}
else if(flag == 1) /** 圆心在内部*/
{
p[n] = p[0]; /** 边界处理*/
for(int i = 0; i < n; i++) /** 遍历所有的边 */
{
if(dcmp(DistanceToSegment(c.center, p[i], p[i+1])-c.radius) < 0)
{
return false;
}
}
return true;
}
else return false; /** 圆心在外部*/
} int main()
{
int n;
while(scanf("%d", &n) != EOF)
{
if(n < 3) break; /** 忠告:输入时注意顺序, 不要脑残。。。*/
scanf("%lf%lf%lf", &c.radius, &c.center.x, &c.center.y);
for(int i = 0; i < n; i++)
scanf("%lf%lf", &p[i].x, &p[i].y); bool flag = isConvex(p, n); /** 判断是否是凸多边形*/
if(flag)
{
flag = isCircleInConvex(p, n, c);
if(flag) printf("PEG WILL FIT\n");
else printf("PEG WILL NOT FIT\n");
}
else printf("HOLE IS ILL-FORMED\n");
}
return 0;
}







POJ 1584 A Round Peg in a Ground Hole【计算几何=_=你值得一虐】的更多相关文章

  1. POJ 1584 A Round Peg in a Ground Hole 判断凸多边形 点到线段距离 点在多边形内

    首先判断是不是凸多边形 然后判断圆是否在凸多边形内 不知道给出的点是顺时针还是逆时针,所以用判断是否在多边形内的模板,不用是否在凸多边形内的模板 POJ 1584 A Round Peg in a G ...

  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: 4438   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: 5456   Acc ...

  4. 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 ...

  5. POJ - 1584 A Round Peg in a Ground Hole(判断凸多边形,点到线段距离,点在多边形内)

    http://poj.org/problem?id=1584 题意 按照顺时针或逆时针方向输入一个n边形的顶点坐标集,先判断这个n边形是否为凸包. 再给定一个圆形(圆心坐标和半径),判断这个圆是否完全 ...

  6. POJ 1584 A Round Peg in a Ground Hole --判定点在形内形外形上

    题意: 给一个圆和一个多边形,多边形点可能按顺时针给出,也可能按逆时针给出,先判断多边形是否为凸包,再判断圆是否在凸包内. 解法: 先判是否为凸包,沿着i=0~n,先得出初始方向dir,dir=1为逆 ...

  7. 简单几何(点的位置) POJ 1584 A Round Peg in a Ground Hole

    题目传送门 题意:判断给定的多边形是否为凸的,peg(pig?)是否在多边形内,且以其为圆心的圆不超出多边形(擦着边也不行). 分析:判断凸多边形就用凸包,看看点集的个数是否为n.在多边形内用叉积方向 ...

  8. POJ 1584 A Round Peg in a Ground Hole

    先判断是不是N多边形,求一下凸包,如果所有点都用上了,那么就是凸多边形 判断圆是否在多边形内, 先排除圆心在多边形外的情况 剩下的情况可以利用圆心到每条边的最短距离与半径的大小来判断 #include ...

  9. 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 ...

随机推荐

  1. JS方面重点摘要(二)

    1.函数声明与函数表达式 (1)变量声明会置顶提前,但赋值仍在原地方(2)函数声明同变量声明一样会提前:但是,函数表达式没有提前,就相当于平时的变量赋值(3)函数声明会覆盖变量声明,但不会覆盖变量赋值 ...

  2. hibernate学习系列-----(3)Session 缓存和持久化生命周期以及Session 基本操作

    Session缓存原理 为了能够在控制台更好的看到我们的hibernate干了些什么,可以在hibernate.cfg.xml文件中写入如下配置: <!-- print all generate ...

  3. C#如何改变字符串编码

    public string UTF8ToGB2312(string str)        {            try            {                    Encod ...

  4. 已加载“C:\Windows\SysWOW64\ntdll.dll”。无法查找或打开 PDB 文件。

    “Win32Project3.exe”(Win32): 已加载“D:\software\VS2013\VS2013 文档\Win32Project3\Debug\Win32Project3.exe”. ...

  5. Nginx 简单的负载均衡配置演示样例

    近期在做开放查询应用的时候,因为数据两天特别多,两千多万条呢,用户訪问需求也比較大,所以就用nginx做了 负载均衡,以下是改动之后的相关内容. http://www.cnblogs.com/xiao ...

  6. 【Excle数据透视表】如何在数据透视表顶部显示列总计数据

    解决方案 创建组并修改组名称为“合计” 如下图:原始数据透视表 步骤 选中列标签区域→右键→组合 修改组合的名称为“合计” 此时底部会有一个合计汇总项,只需要单击数据透视表任意单元格→数据透视表工具→ ...

  7. 安装MacOS到虚拟机

    [TOC] 系统版本历史 4. 升级系统到10.12.6版本 时间:2017年9月21日 15:58:55 大小:VMDK(7.63 GB) 变动: 升级系统到10.12.6版本 3. 降低内存到6G ...

  8. Atitit.struts排除url 的设计and 原理 自定义filter 排除特定url

    Atitit.struts排除url 的设计and 原理 自定义filter 排除特定url 1.1. 原理流程1 2. Invoke1 3. StrutsX2 1.1. 原理流程 读取struts配 ...

  9. SRIO常用缩写

    HELLO:Header Encoded Logical Layer Optimized (HELLO) format FTYPE:format type TTYPE:transaction type ...

  10. Windows进程间通信--共享内存映射文件(FileMapping)--VS2012下发送和接收

    之前以为两个互不相关的程序a.exe b.exe通信就只能通过网络,人家说可以通过发消息,我还深以为不然,对此,我表示万分惭愧. 之前课本上说的进程间通信,有共享内存.管道等之类的,但没有自己操刀写过 ...