Reading test instructions is critical, 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.
First to understand what a stable convex hull is.
For example, there are 4 points:
These four points are some of the points on a convex hull, and they are indeed a convex hull after they are connected, but they are not stable,
We found that the convex hull is not stable when there is a point on the convex hull that has only two points of the end point, because it can introduce a point outside the edge and form a new convex hull. But once there are three points on one side, it is impossible to find a point that expands it into a new convex hull, otherwise the new polygon will be concave.
The following is a typical stable convex hull:
Then the practice of the problem is finally clear. That is, the new convex hull given this pile of points, and then determine whether there are at least 3 points on each side of the convex hull, if one edge does not meet the conditions, then output No. otherwise yes.
Their own do not know where the wrong change, attached to the Big God Code:
#include <iostream>#include <cstdio>#include <cmath>#include <cstring>#include <algorithm>#define EPS 1e-8using namespace STD;structpoint{Doublex, y;}; Point p[1010],Stack[1010];intN,top;Doublemulti (point P1, point P2, point p3) {return(p2.x-p1.x) * (P3.Y-P1.Y)-(P2.Y-P1.Y) * (p3.x-p1.x);}DoubleDis (point A, point B) {return sqrt((a.x-b.x) * (a.x-b.x) + (A.Y-B.Y) * (A.Y-B.Y));intcmpConst void*a,Const void*B) {Point c = * (point *) A; Point d = * (point *) b;Doublek = multi (p[0], C, D);if(K <0|| (!k && Dis (c, p[0]) > Dis (d, p[0])))return 1;return-1;}voidConvex () { for(inti =1; i < N; i++) {Point temp;if(P[i].y < p[0].y | | (P[i].y = = p[0].y && p[i].x < p[0].x)) {temp = P[i]; P[i] = p[0]; p[0] = temp; }} qsort (P +1N1,sizeof(p[0]), CMP);Stack[0] = p[0];Stack[1] = p[1]; top =1; for(inti =2; i < N; i++) { while(Top >=1&& multi (Stack[Top-1],Stack[Top], P[i]) <0) top--;//collinear points are also pressed into the convex bag;top++;Stack[Top] = p[i]; }}BOOLJudge () { for(intI=1; i<top;i++) {if((multi (Stack[I1],Stack[i+1],Stack[i])! =0&& (multi (Stack[I],Stack[i+2],Stack[i+1]))!=0)//Determine if there are at least three points on each side; return false; }return true;}intMain () {intTCin>>t; while(t--) {Cin>>N; for(intI=0; i<n;i++)scanf("%LF%LF", &P[I].X,&P[I].Y);if(n<6)puts("NO");Else{Convex ();if(Judge ())puts("YES");Else puts("NO"); } }return 0;}
POJ 1228 Grandpa ' s Estate (Stable convex bag)