POJ 1228 Grandpa ' s Estate (convex bag)

Source: Internet
Author: User

Grandpa ' s Estate
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 11508 Accepted: 3188

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


Test Instructions: Enter a point on the convex hull (no point inside the convex hull, either the convex hull vertex or the point on the convex edge) to determine whether the convex hull is stable. The so-called stability is to determine whether the original convex hull can be dotted, a larger convex hull, and the convex package contains all the points on the original convex hull.


Puzzle: Each edge of the convex hull contains an endpoint with at least 3 points to stabilize the convex hull at a constant point. We just need to determine if there are any remaining points on each side of the convex hull.


#include <cstring> #include <iostream> #include <cstdio> #include <algorithm> #include < cmath> #include <vector> #define INF 0x3f3f3f3f#define _sign (x) ((x) >eps?1: (((x) <-eps?2:0)) using    namespace Std;const int maxn = 1030;struct Point {double x, y;        Point () {}, point (double _x,double _y) {x = _x;    y = _y;    } Point operator-(const point &b) const {return point (X-B.X,Y-B.Y);    }//Fork Product Double operator ^ (const point &b) const {return x*b.y-y*b.x;    }//dot product double operator * (const point &b) Const {return x*b.x + y*b.y;        }//Rotation angle B (radian value) around origin, after x, y change void transxy (double B) {Double tx = X,ty = y;        x = Tx*cos (b)-Ty*sin (b);    y = Tx*sin (b) + ty*cos (b); }}; Point L[maxn];int stack[maxn],top;int n;double Dist (point A,point b) {return sqrt ((a.x-b.x) * (a.x-b.x) + (A.Y-B.Y) * (a.y-b . y));} Double multi (point P1, point P2, point p3) {return (p2.x-p1.x) * (P3.Y-P1.Y)-(P2.Y-P1.Y) * (p3.x-p1.x);}    int SGN (double x) {if (Fabs (x) <1e-12) return 0;    if (x<0) return-1; return 1;}    The polar order relative to l[0] bool _cmp (point p1,point p2) {Double tmp = (p1-l[0]) ^ (p2-l[0]);    if (SGN (TMP) >0) return true;    else if (SGN (TMP) ==0&AMP;&AMP;SGN (Dist (p1,l[0])-dist (p2,l[0])) <= 0) return true; else return false;}    void Graham (int m) {if (m<=1) return;    Point P0;    int k = 0; P0 = l[0];//Find the bottom of a dot for (int i=1; i<m; i++) {if ((P0.Y&GT;L[I].Y) | | (p0.y==l[i].y&&p0.x>l[i].x))            {p0 = L[i];        K = i;    }} swap (l[k],l[0]);    Sort (l+1,l+m,_cmp);        if (m==1) {top=1,stack[0] = 0;    Return        } if (m==2) {top=2,stack[0]=0,stack[1]=1;    return;    } stack[0]=0;    Stack[1]=1;    top=2; for (int i=2, i<m; i++) {while (TOP&GT;1&AMP;&AMP;SGN ((l[stack[top-1]]-l[stack[top-2]) ^ (L[i]-l[stack[top-2]])) &L        t;=0) top--;    stack[top++] = i;   }}int Main () { Freopen ("Test.in", "R", stdin);    int t;    cin>>t;        while (t--) {scanf ("%d", &n);        for (int i=0; i<n; i++) {scanf ("%lf%lf", &l[i].x,&l[i].y);            } if (n<6) {printf ("no\n");        Continue        } Graham (n);        BOOL Flag=1;            for (int i=0; i<top; i++) {int u=stack[i],v=stack[(i+1)%top];            flag=1; Determine if the remaining points exist at least one point on the edge for (int j=0; j<n; J + +) {if (j==u| |                J==V) continue;                    if (multi (l[u],l[j],l[v]) ==0) {flag=0;                Break        }} if (flag) break; } printf ("%s\n", flag==0?)    YES ":" NO "); } return 0;}


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

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.