POJ 1228 Grandpa ' s Estate (convex bag)

Source: Internet
Author: User

Grandpa ' s Estate
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 11289 Accepted: 3117

Description

Being the only living descendant of he grandfather, Kamran the believer inherited all of the Grandpa ' s belongings. The most valuable one is a piece of convex polygon shaped farm in the grandpa ' s birth village. The farm was originally separated from the neighboring farms by a thick rope hooked to some spikes (big nails) placed on t He boundary of the polygon. But if Kamran went to visit his farm, he noticed that the rope and some spikes is missing. Your task is-to-write a program-to-Kamran decide whether the boundary of his farm can being exactly determined only by T He remaining spikes.

Input

The first line of the input file contains a single integer t (1 <= t <=), the number of test cases, followed by t He input data for each test case. The first line of all test case contains a integer n (1 <= n <=) which is the number of remaining spikes. Next, there is n lines, one line per spike, each containing a pair of integers which is x and y coordinates of the spike .

Output

There should is one output line per test case containing YES or NO depending on whether the boundary of the farm can is UN Iquely determined from the input.

Sample Input

16 0 01 23 42 02 4 5 0

Sample Output

NO

Source

Tehran 2002 Preliminary
The main topic: given n points, are convex hull vertices, asked whether the convex hull is a stable convex hull, is the only way to determine a convex bag: just beginning to think how to determine whether it is convex bag is finished, handed several times are WA, and then go online a look, the original is not such ... is to stabilize the convex hull, if the given vertex is uniquely determined by a convex hull, then the number of vertices on each edge of the polygon must be greater than or equal to three (including the endpoint), only in this way can be guaranteed to be stable. In figure one, if there is no third point between AB, then it is possible to appear a point e also make the original figure is convex, so it is unstable, figure two is stable, with these points, he can only determine a convex bag. It's much easier to write code after you know it. My Code:
/************************************************************************* > File Name:poj_1228.cpp > Author:howe_young > Mail: [email protected] > Created time:2015 Year May 07 Thursday 16:44 36 sec ************************************************************************/#include<cstdio>#include<iostream>#include<cstring>#include<cmath>#include<cstdlib>#include<algorithm>#defineEPS 1e-8using namespacestd;Const intMAXN =1004;structpoint{Doublex, y;}; Point P[MAXN], CONVEX[MAXN];DoubleMin (DoubleADoubleb) {    returnA < b?a:b;}DoubleMax (DoubleADoubleb) {    returna > B?a:b;}intSgnDoublex) {    if(Fabs (x) <EPS)return 0; returnX <0? -1:1;}DoubleX_multi (Point P1, point P2, point p3) {return(p3.x-p1.x) * (P2.Y-P1.Y)-(p2.x-p1.x) * (P3.Y-p1.y);}BOOLcmpConstPoint P1,ConstPoint p2) {    return(P1.y = = P2.y && p1.x < p2.x) | | P1.y <p2.y);}voidConvex_hull (Point *p, point *convex,intNint&Len) {sort (p, p+N, CMP); inttop =1; convex[0] = p[0]; convex[1] = p[1]; //finding the lower part convex hull of convex hull     for(inti =2; I < n; i++)    {         while(Top >0&& sgn (X_multi (Convex[top-1], Convex[top], p[i]) <=0)//greater than 0 is counterclockwise, less than 0 is clockwisetop--; convex[++top] =P[i]; }    intTMP =top; //find the upper part of the convex hull, because my comparison function is write y first, so the upper and lower parts, of course, can also be the X-priority, this is the left and right part of the     for(inti = n-2; I >=0; i--)    {         while(Top > TMP && sgn (X_multi (Convex[top-1], Convex[top], p[i]) <=0)//greater than 0 is counterclockwise, less than 0 is clockwisetop--; convex[++top] = P[i];//storing points in a convex bag} len=top;}BOOLOn_segment (Point P1, point P2, point P3)//determine if the P3 is on line p1p2{    DoubleMinx, Miny, Maxx, Maxy; Minx=Min (p1.x, p2.x); Maxx=Max (p1.x, p2.x); Miny=Min (P1.Y, P2.Y); Maxy=Max (P1.Y, P2.Y); return(SGN (X_multi (P1, p2, p3)) = =0&& (SGN (P3.x-minx) >=0&& sgn (P3.x-maxx) <=0&& sgn (p3.y-miny) >=0&& sgn (P3.y-maxy) <=0));}BOOLCheck (point *p, point P1, point P2,intN) {    intCNT =0;  for(inti =0; I < n; i++)    {        if(On_segment (P1, p2, p[i]) CNT++; }    if(cnt = = N)//if a given point becomes a line, it does not conform to the        return false; returnCNT >=3;}intMain () {intKase, N; scanf ("%d", &Kase);  while(kase--) {scanf ("%d", &N);  for(inti =0; I < n; i++) scanf ("%LF%LF", &p[i].x, &p[i].y); intLen; if(N <=5)//N <= 5 Before the point is indeterminate{puts ("NO"); Continue;        } convex_hull (P, Convex, N, Len); Convex[len]= convex[0]; BOOLFlag =false;  for(inti =0; i < Len; i++)//check each edge in the convex hull        {            if(!check (P, Convex[i], Convex[i +1], N)) {flag=true;  Break; }        }        if(!flag) puts ("YES"); Elseputs ("NO"); }    return 0;}
View Code

POJ 1228 Grandpa ' s Estate (convex bag)

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.