Poj 1584 a round peg in a ground hole]

Source: Internet
Author: User
Link: http://poj.org/problem? Id = 1584 http://acm.hust.edu.cn/vjudge/contest/view.action? Cid = 22013 # Problem/DA round peg in a ground hole
Time limit:1000 ms   Memory limit:10000 K
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 Compute S 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 desired s 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 wowould cross one or more edges of the hole ), then the filled-in-hole wocould 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.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

Source

Mid-Atlantic 2003

Question:
Give you a polygon with N points and a nail.
Determine whether a nail is inside a polygon


Note: first, enter the number of points in the polygon,

Enter the nail radius, and then the coordinate tot.

Ideas:
1. first determine whether a polygon is a convex polygon,
If not, the output hole is ill-formed
If yes, continue to judge
2. (1) Determine whether the center of the circle is outside the convex polygon.
If it is outside, false is directly returned.
Returns true if it is on the edge and the radius is = 0.
If the radius is not 0, false is returned.
If it is inside, the distance between the center and each edge line segment is traversed to be greater than or equal to the radius.
True is returned if all conditions are met.
Otherwise, false is returned.
If the nail can be mounted, the output will be peg fit
Otherwise, output peg will not fit. Advice: Don't NC

Related test questions: HDU 2108 shape of HDU [Determining whether a polygon is a convex polygon TEMPLATE]

Sgu Theodore Roosevelt [determines whether a vertex is in a convex polygon TEMPLATE]

Sgu 1348 goat in the garden 2 [distance from a point to a line segment]

Start WAF until you find the three basic questions.


/*************************************** * ********** Accepted192 kb0 MSC ++ 4208 B2013-07-28 16:02:24: give you a polygon containing N points and a nail to determine whether the nail is inside the polygon. Note: The first line of the input first inputs the points of the polygon, and then inputs the nail radius, then the idea of coordinate Tot is: 1. first, judge whether the polygon is a convex polygon. If not, the output hole is ill-formed. If yes, continue to Judge 2. (1) Determine whether the center is outside the convex polygon. If it is outside, false is directly returned. If the Center is on the edge and the radius is = 0, true is returned. If it is inside, false is returned, indicates whether the distance from the center of the traversal to each edge line segment is greater than or equal to the radius. If all the radius is satisfied, true is returned. Otherwise, false is returned. If the nail can be mounted, the peg will fit is output. Otherwise, the peg will be output. 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 re Turn x <0? -1: 1;} bool operator = (const point & A, const point & B) {return DCMP (. x-B.x) = 0 & DCMP (. y-B.y) = 0;} double cross (point a, point B)/** Cross Product */{return. x * B. y-. y * B. x;} double dot (point a, point B)/** dot product */{return. x * B. X +. y * B. y;} double length (point a) {return SQRT (. x *. X +. y *. y);}/** determine whether the polygon is a convex polygon [including colons] */bool isconvex (point * P, int N) {P [N] = P [0]; // boundary processing p [n + 1] = P [1]; // note that % N can also be used for processing, Subscript starts from 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) // here it can be collocated {return false;} Now = next; // note the record critical condition} return true;}/** point whether there are [boundary] */INT ispointinconvex (point * P, int N, 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;/** point out */} else if (next * Now = 0) {return 0;/** point on the edge */} Now = next ;} return flag;/** point in the interior */}/** determine the distance from point P to line 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); // advice: do not have brains/2 ...} /** determine whether the circle is inside the convex polygon and the tangent can also be */bool iscircleinconvex (point * P, int N, Circle C) {int flag = ispointinconvex (p, n, c. center);/** determine the center of the center */If (flag = 0)/** the center of the center is on the edge */{If (C. radius = 0) return true; else return false;} else if (flag = 1)/** center inside */{P [N] = P [0]; /** boundary Processing */For (INT I = 0; I <n; I ++)/** traverse all edges */{If (DCMP (distancetosegment (C. center, P [I], p [I + 1])-C. radius) <0) {return false;} return true;} else return false;/** the center of the center is external */} int main () {int N; while (scanf ("% d", & N )! = EOF) {If (n <3) break;/** tips... */Scanf ("% lf", & C. radius, & C. center. x, & C. center. y); For (INT I = 0; I <n; I ++) scanf ("% lf", & P [I]. x, & P [I]. y); bool flag = isconvex (p, n);/** determine whether it is a convex polygon */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 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.