"POJ 1584" a Round Peg in a Ground Hole (convex hull + Award circle in convex package)

Source: Internet
Author: User

"POJ 1584" a Round Peg in a Ground Hole (convex hull + Award circle in convex package)

The problem is a big hole. The long obvious is for me this English slag preparation ...

The general meaning is to give the point of a polygon clockwise or counterclockwise to determine whether a convex hull is given a circle (center coordinate + radius) ask this circle in the not polygon

First counterclockwise Not sure my approach is to enter the first to judge the clockwise or counter-clockwise input and then all turn counterclockwise to go is based on the two conditions into the different pieces of lifting point end points and add and subtract (see Code

The fork of the convex package can be used to determine if the convex hull of the cross-clockwise so that if it is a bump vector must be counterclockwise rotation at the same time can also judge the center is not in the convex hull to see the current starting point and the center of the Vector fork into the current side is negative (clockwise) the center of the polygon (the edge is also calculated

If you do not directly output HOLE is ill-formed for convex hull

If the center is not in the convex hull output peg would not FIT

Otherwise, determine whether the circle is completely convex package to enumerate the convex hull each edge if there is an edge and the center distance is less than the radius of the circle to explain the circle is no longer convex in the package if you can traverse all the edges in the convex package

The distance from the point to the line segment is multiplied by the vector of two segments of the segment and the pity Dorado, which can be obtained (H*W)/2 = L1XL2/2 W is the parallelogram area of the segment length x for the fork by the Triangle and the point to the line segment is the height of the triangle. H = (L1XL2 /w This is the distance formula for point-to-line segments

This completes the program

PS: Found a good thing everyone wa don't want to be able to test

http://midatl.fireduck.com/archive/2003/problems/MidAtlantic-2003/problem-D/


The code is as follows:


#include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <vector > #include <algorithm> #include <cmath> #define ESP 1e-5using namespace std;typedef struct point point;    typedef struct LINE Line;struct line{double x, y;    BOOL operator > (const line a) const//clockwise {return x*a.y-y*a.x > ESP;    } BOOL operator < (const line a) const//counterclockwise {return x*a.y-y*a.x <-esp;    } bool operator = = (Const line a) const//collinear {return x*a.y-y*a.x < ESP && x*a.y-y*a.x >-esp;    } Double operator * (const line a) const//fork by {return fabs (x*a.y-y*a.x);    }};struct point{double x, y;        Line operator-(const point a) const//get two dot vector {line L;        l.x = x-a.x;        L.y = Y-A.Y;    return l;    } double operator + (const point a) const//distance between two points {return (x-a.x) * (x-a.x) + (Y-A.Y) * (Y-A.Y); }}; Point yx;double r;vector <Point> vc;int n;intCal (int low,int high,int STP)//Determine whether a convex polygon is at the same time to determine whether the center is inside {line l1,l2;    Point P1,p2,p3;    int i;    int f = 1;    P1 = Vc[low];    P2 = VC[LOW+STP];    L1 = P2-P1;    L2 = Yx-p1;    if (L2 > L1) f = 0;        for (i = low+stp*2; I! = HIGH+STP; i + = stp) {p3 = vc[i];        L1 = P2-P1;        L2 = P3-p1;        if (L2 > L1) return 0;        L1 = p3-p2;        L2 = YX-P2;        if (f && L2 > L1) f = 0;        P1 = p2;    P2 = p3; } return f+1;}    BOOL Challenge ()//Determine if the circle is within the polygon {int i;    Point P;    Line L1,L2;    p = vc[0];        for (i = 1; i < vc.size (); ++i) {L1 = P-yx;        L2 = Vc[i]-yx;        if ((L1*L2)/sqrt (vc[i]+p)-R <-esp) return 0;    p = vc[i]; } return 1;}    int main () {freopen ("in.in", "R", stdin);    Point Tmp,pt,p1,p2;    Line L1,L2;    int F;        while (~SCANF ("%d", &n) && n >= 3) {f = 0;        Vc.clear ();        scanf ("%lf%lf%lf", &r,&yx.x,&yx.y); scanf ("%lf%lf", &tmP.X,&AMP;TMP.Y);        Vc.push_back (TMP);        P1 = tmp;        scanf ("%lf%lf", &p2.x,&p2.y);        Vc.push_back (p2);        N-= 2;            while (n--) {scanf ("%lf%lf", &AMP;PT.X,&AMP;PT.Y);            Vc.push_back (PT);                if (!f) {L1 = P2-p1;                L2 = Pt-p1;                if (L1 > L2) F = 1;            else if (L1 < L2) F =-1;            } p1 = p2;        P2 = pt;        } vc.push_back (TMP); if (f = = 1) F = cal (0,vc.size () -1,1);//Clockwise input else if (f = =-1) F = cal (Vc.size () -1,0,-1);//counterclockwise input else F = 0;//            Does not constitute a convex polygon if (f = = 2) {if (Challenge ()) puts ("PEG would FIT");        Else puts ("PEG would not FIT");        } else if (f = = 1) puts ("PEG would not FIT");    Else puts ("HOLE is ill-formed"); } return 0;}








Xiao Kee:

So late to write this puzzle think oneself also pretty spell of tomorrow morning, the training will also go up to talk (not you think of it kind of. I am a green onion ... Exercise is also counted

At this point, the training program POJ part of the primary end of the night. From last summer vacation to now one year I am also amazed at my progress but it's not enough to say a little faster than the average person compared to those Daniel schools. Can only hehe then be abused ... Multi-school can see that there is a previous time with Yamashina to do a network game (team is really weaker than others with their 14-level ratio is also too bad too much also is normal it is often what things are the more efforts to the clouds will dissipate but gradually you find the wall is blocked to continue to climb can go over the wall you also found a river behind There is a river and a mountain ... That's the way this pyramid has no top floor. No one knows how high it will climb or not, but the weak is still at the bottom of the tower ...

Here's a little bit of emotion. Should not be able to see it ... Can't see I can't see I can't see me ... Now that you've chosen this road, it's good to crawl on your knees, at least still!

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

"POJ 1584" a Round Peg in a Ground Hole (convex hull + Award circle in convex package)

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.