Grandpa ' s Estate
Time Limit: 1000MS |
|
Memory Limit: 10000K |
Total Submissions: 12204 |
|
Accepted: 3430 |
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
The subject is difficult to understand.
Test instructions: Stable convex hull problem: give n points, ask whether the convex hull formed is "stable".
The so-called stability Determine whether you can add a bit to the original convex hull, and get a larger convex hull, and the convex package contains all the points on the original convex package.
This explanation feels easy to understand, quoted by: http://blog.csdn.net/acdreamers/article/details/10023615/
My view is that at least one point is needed on the side of the edge. In that case it will be stable.
In my humble opinion. The solution on the internet is problematic. Give me a solution and a group of other people's test data. The POJ data may be a bit watery. Many of the solutions on the Web are added to the top of the convex hull, but not the vertex points. Then use two cross product condition to judge.
I am directly enumerating each edge, then enumerate all points, in addition to the vertex at least one point at the edge of the line (the topic said that the point is in the convex hull vertex or edge, so that it is not meaningful to use the online solution to the convex hull, because it is already in order, all the points added once, stack should be p).
Adding a condition is that the points cannot be less than 6, because even the triangles need at least 6 points to stabilize.
Test data:
1
6
0 0 1 1 2 2 3 3 2 3 0 3
NO
#include<iostream>#include<cstdio>#include<cstring>#include<math.h>#include<algorithm>#include<stdlib.h>using namespacestd;Const intN =1005;Const DoubleEPS = 1e-8;structPoint {intx, y;} P[n],stack[n];structline{Point A, B;} Line;intN;intCross (Point A,point b,point c) {return(a.x-c.x) * (B.Y-C.Y)-(A.Y-C.Y) * (b.x-c.x);}DoubleDis (point a,point b) {returnsqrt ((Double) ((a.x-b.x) * (a.x-b.x) + (A.Y-B.Y) * (a.y-B.Y))) ;}intCMP (point A,point b) {if(Cross (a,b,p[0]) >0)return 1; if(Cross (a,b,p[0])==0&&dis (b,p[0])-dis (a,p[0]) >eps)return 1; return 0;}BOOLGraham () {intk=0; for(intI=1; i<n;i++){ if(p[i].y<p[k].y| | (P[I].Y==P[K].Y) && (p[i].x<p[k].x)) k=i; } Swap (p[0],p[k]); Sort (P+1, p+n,cmp); inttop =2; stack[0] = p[0]; stack[1] = p[1]; stack[2] = p[2]; for(intI=3; i<n;i++){ while(top>=1&&cross (p[i],stack[top],stack[top-1]) >=0) top--; stack[++top] =P[i]; } intCNT; Stack[top+1] = stack[0]; for(intI=0; i<=top;i++) {Line.a=Stack[i]; line.b= stack[i+1]; CNT=0; for(intj=0; j<n;j++){ if(line.a.x = = p[j].x && line.a.y = = p[j].y)Continue;///Remove itself if(line.b.x = = p[j].x && line.b.y = = p[j].y)Continue; if(Cross (line.a,line.b,p[j]) = =0) {CNT++; Break; } } if(cnt==0)return false; } return true;}intMain () {inttcase; scanf ("%d",&tcase); while(tcase--) {scanf ("%d",&N); for(intI=0; i<n;i++) {scanf ("%d%d",&p[i].x,&p[i].y); } if(n<6) {printf ("no\n");Continue; } BOOLAns =Graham (); if(ANS) printf ("yes\n"); Elseprintf"no\n"); } return 0;}
POJ 1228 (Stable convex bag)