poj1584(判断多边形是否凸包,判断圆是否在多边形内)
来源:互联网 发布:分析网站制订优化目标 编辑:程序博客网 时间:2024/05/19 06:51
A Round Peg in a Ground Hole
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 5426 Accepted: 1723
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).
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.
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
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.01.0 1.02.0 2.01.75 2.01.0 3.00.0 2.05 1.5 1.5 2.01.0 1.02.0 2.01.75 2.51.0 3.00.0 2.01
Sample Output
HOLE IS ILL-FORMEDPEG WILL NOT FIT
题意见标题。
#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>#include <iostream>#include <cmath>#include <queue>#include <map>#include <stack>#include <list>#include <vector>#include <ctime>#define LL __int64#define eps 1e-8#define pi acos(-1)using namespace std;struct point{double x,y;point (double x=0,double y=0):x(x),y(y){} };point operator -(point a,point b){return point(b.x-a.x,b.y-a.y);}int dcmp(double x){if (fabs(x)<eps) return 0;if (x<0) return -1;return 1;}double across(point a,point b){return a.x*b.y-a.y*b.x;}double pd(point p0,point p1,point p2){return across(p1-p0,p2-p0);}double length(point a){return sqrt(a.x*a.x+a.y*a.y);}point o,p[10000];int main(){int n,i;double r;while (~scanf("%d",&n) && n>=3){scanf("%lf%lf%lf",&r,&o.x,&o.y);for (i=0;i<n;i++)scanf("%lf%lf",&p[i].x,&p[i].y);p[n].x=p[0].x;p[n].y=p[0].y;p[n+1].x=p[1].x;p[n+1].y=p[1].y;int t=0;//t=1for (i=2;i<=n+1;i++){if (dcmp(pd(p[i-2],p[i-1],p[i]))==1){t=1;break;}else if (dcmp(pd(p[i-2],p[i-1],p[i]))==-1){t=-1;break;}}int flag=0;if (t!=0){for (;i<=n+1;i++){if (dcmp(pd(p[i-2],p[i-1],p[i]))!=t && dcmp(pd(p[i-2],p[i-1],p[i]))!=0){flag=1;break;}}}if (flag || t==0)printf("HOLE IS ILL-FORMED\n");else{for (i=1;i<=n+1;i++){if (dcmp(pd(p[i-1],p[i],o))!=t && dcmp(pd(p[i-1],p[i],o))!=0){flag=1;break;}}if (!flag){for (i=0;i<n;i++){point v1=p[i+1]-p[i];point v2=o-p[i];double s=fabs(across(v1,v2)/length(v1));if (s<r){flag=1;break;}}}if(flag==1) printf("PEG WILL NOT FIT\n"); else printf("PEG WILL FIT\n");}}return 0;}
0 0
- poj1584(判断多边形是否凸包,判断圆是否在多边形内)
- POJ1584 A Round Peg in a Ground Hole 判断多边形是否为凸多边形,判断凸多边形是否在圆内
- 判断点是否在多边形内
- 判断点是否在多边形内
- 判断一个点是否在多边形内
- 判断点是否在多边形内
- 判断点是否在多边形内
- 判断点是否在多边形内
- 判断某个点是否在多边形内
- zoj1081判断点是否在多边形内
- 判断点是否在多边形内
- 判断点是否在多边形内
- 判断点是否在多边形内
- 判断点是否在多边形内
- 判断点是否在多边形内
- 判断点是否在多边形内
- 判断点是否在多边形内
- 判断点是否在多边形内
- 黑马程序员_java_06_java网络编程
- flash-热风焊盘的制作
- 各种操作 整理
- CSS3 @font-face
- Linux开发环境搭建与使用——Linux 常用命令的使用
- poj1584(判断多边形是否凸包,判断圆是否在多边形内)
- 黑马程序员_java_07_java面向对象
- Qt 按钮如何实现背景图片的加载
- mongodb 学习笔记及常用命令
- hdu 1542 Atlantis 线段树求面积并,,,尼玛数据真坑人,数组千万不能开小!
- 机器视觉常用词及专业化词汇
- adb logcat命令查看并过滤android输出log
- 黑马程序员_java_09_java反射
- 内排序小结