Grandpa ' s Estate-poj 1228 (Stable convex bag)

Source: Internet
Author: User

Just start to see this topic do not know what east, after looking at the problem of the big God to know is the stability convex hull, what is stable convex package? 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. Know this thing is simple, directly out of the convex hull, and then determine whether the point on each edge is more than three points on the line.

The code is as follows:

=============================================================================================================== =============

#include <stdio.h>#include<string.h>#include<algorithm>#include<math.h>using namespacestd;Const DoubleEPS = 1e- -;Const intMAXN =1007;Const intOO = 1e9+7;intSTA[MAXN], top;structpoint{Doublex, y; Point (Doublex=0,Doubley=0): X (x), Y (y) {} pointoperator- (ConstPoint &t)Const{        returnPoint (X-t.x, yt.y); }    Double operator*(ConstPoint &t)Const{        returnX*t.x + y*T.y; }    Double operator^(ConstPoint &t)Const{        returnx*t.y-y*T.x; }}P[MAXN];intSign (Doublet) {    if(T > EPS)return 1; if(Fabs (T) < EPS)return 0; return-1;}DoubleDist (Point A, point B) {returnsqrt (A-B) * (Ab));}BOOLCMP (Point A, point B) {intt = sign (a-p[0]) ^ (b-p[0])); if(T = =0)        returnDist (A, p[0]) < Dist (b, p[0]); returnT >0;}voidGraham (intN) {    intk=0;  for(intI=0; i<n; i++)    {        if(P[k].y>p[i].y | | (sign (p[k].y-p[i].y) = =0&& p[k].x >p[i].x)) K=i; } Swap (p[0], p[k]); Sort (P+1, p+N, CMP); sta[0]=0, sta[1]=1, top=1; if(N <2) {Top= N1; return ; }     for(intI=2; i<n; i++)    {         while(top>0&& sign ((P[i]-p[sta[top]) ^ (p[sta[top-1]]-p[sta[top]]) <=0) Top--; sta[++top] =i; }}intMain () {intT, N, I, J; scanf ("%d", &T);  while(t--) {scanf ("%d", &N);  for(i=0; i<n; i++) scanf ("%LF%LF", &p[i].x, &p[i].y);        Graham (N); sta[++top] = sta[0];  for(i=0; i<top; i++)        {            intS=sta[i], e=sta[i+1];  for(j=0; j<n; J + +)            {                if(J==s | | j==e)Continue; if(sign (p[s]-p[e) ^ (P[j]-p[e]) = =0)                     Break; }            if(J = =N) Break; }        if(I < top | | Top <3) printf ("no\n"); Elseprintf ("yes\n"); }    return 0;}

Grandpa ' s Estate-poj 1228 (Stable 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.