POJ1584-A round peg in a ground hole)

Source: Internet
Author: User
A round peg in a ground hole
Time limit:1000 ms   Memory limit:10000 K
Total submissions:5301   Accepted:1662

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 specified s need to be scrapped or if they can be salvaged by filling a part of the hole with a mixture wood of 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
Question: give you n polygon points and ask if you are a convex bag. If not, output hole is ill-formed to determine whether the circle is in the convex bag. Train of Thought: it is simple to determine the convex hull. If the circle is within the convex hull, for each line segment (vector, counterclockwise) of the convex hull, the center distance is greater than the radius, and on the left.
#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <vector>#include <algorithm>using namespace std;#define REP(_,a,b) for(int _ = (a); _ < (b); _++)#define sz(s)  (int)((s).size())typedef long long ll;const double eps = 1e-10;const int maxn = 50;int n;struct Point{double x,y;Point(double x=0.0,double y = 0.0):x(x),y(y){}};Point vP[maxn];typedef Point Vector;struct Line {Point P;Vector v;double ang;Line(){}Line(Point P,Vector v):P(P),v(v){ang = atan2(v.y,v.x);}bool operator <(const Line&L) const{return ang < L.ang;}};Line LX[maxn],LY[maxn];Vector operator + (Vector A,Vector B) {return Vector(A.x+B.x,A.y+B.y);}Vector operator - (Vector A,Vector B){return Vector(A.x-B.x,A.y-B.y);}Vector operator * (Vector A,double p){return Vector(A.x*p,A.y*p);}Vector operator / (Vector A,double p){return Vector(A.x/p,A.y/p);}int dcmp(double x){if(fabs(x) < eps) 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.x-b.x)==0&&dcmp(a.y-b.y)<0;}bool operator == (const Point &a,const Point &b){return dcmp(a.x-b.x)==0&& dcmp(a.y-b.y)==0;}double Dot(Vector A,Vector B) {return A.x*B.x+A.y*B.y;}double Length(Vector A) {return sqrt(Dot(A,A));}double Angle(Vector A,Vector B) {return acos(Dot(A,B)/Length(A)/Length(B));}double Cross(Vector A,Vector B) {return A.x*B.y-A.y*B.x;}Vector Rotate(Vector A,double rad) {return Vector(A.x*cos(rad)-A.y*sin(rad),A.x*sin(rad)+A.y*cos(rad)); }Vector Normal(Vector A) {double L = Length(A);return Vector(-A.y/L,A.x/L);}bool OnSegment(Point p,Point a1,Point a2){return dcmp(Cross(a1-p,a2-p)) == 0 && dcmp(Dot(a1-p,a2-p)) < 0;}Point GetIntersection(Line a,Line b){Vector u = a.P-b.P;double t = Cross(b.v,u) / Cross(a.v,b.v);return a.P+a.v*t;}int ConvexHull(Point* p,int n,Point *ch){sort(p,p+n);int m = 0;for(int i = 0; i < n; i++) {while(m > 1 && dcmp(Cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])) <= 0) m--;ch[m++] = p[i]; }int k = m;for(int i = n-2; i >= 0; i--){while(m > k && dcmp(Cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])) <= 0) m--;ch[m++] = p[i];}if(n > 1) m--;return m;}double a[maxn];void input(){double t;REP(i,0,n)scanf("%lf",&a[i]);LX[0] = Line(Point(0,1.0),Vector(0,-1.0));REP(i,0,n){scanf("%lf",&t);LX[i+1] = Line(Point(t,1.0),Vector(a[i]-t,-1.0));}LX[n+1] = Line(Point(1.0,1.0),Vector(0,-1.0));LY[0] = Line(Point(1.0,0),Vector(-1.0,0));REP(i,0,n)scanf("%lf",&a[i]);REP(i,0,n){scanf("%lf",&t);LY[i+1] = Line(Point(1.0,t),Vector(-1.0,a[i]-t));}LY[n+1] = Line(Point(1.0,1.0),Vector(-1.0,0));}void solve(){double ans = 0;REP(i,1,n+2) {Point a,b,c,d;REP(j,1,n+2) {a = GetIntersection(LX[i-1],LY[j-1]);//cout<<a.x<<" "<<a.y<<endl;b = GetIntersection(LX[i],LY[j-1]);//cout<<b.x<<" "<<a.y<<endl;c = GetIntersection(LX[i],LY[j]);d = GetIntersection(LX[i-1],LY[j]);double area = 0;area = fabs(Cross(a,b)/2+Cross(b,c)/2+Cross(c,d)/2+Cross(d,a)/2);ans = max(area,ans);}}printf("%.6f\n",ans);}int main(){while(~scanf("%d",&n) && n){input();solve();}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.