Grandpa ' s Estate
Time Limit: 1000MS |
|
Memory Limit: 10000K |
Total submissions: 12816 |
|
accepted: 3604 |
Description being the living descendant of his grandfather, Kamran the believer inherited all of the Grandpa ' s Bel Ongings. The most valuable one is a piece of convex polygon shaped farm in the grandpa ' s birth village. The farm is originally separated from the neighboring farms through a thick rope hooked to some spikes (big nails) placed on t He boundary the polygon. But, when Kamran went to visit's his farm, he noticed the rope and some spikes are. Your task is to write a program to help Kamran decide whether the boundary of he farm can be exactly determined only by T He remaining spikes.
Input the ' the ' input file contains a single integer t (1 <= t <=), the number of test cases, Followe D by the input data for each test case. The (a) of each test case contains a integer n (1 <= n <= 1000) which is the number of remaining spikes. Next, there are n lines, one line per spike, each containing a pair of integers which are x and y coordinates of the spike .
Output There should be one output line/test case containing YES or NO depending on whether the boundary of the farm CA N is uniquely determined from the input.
Sample Input
1
6
0 0 1 2 3 4 2 0 2 4 5-
0
Sample Output
NO
To determine whether a convex package has at least three dots per edge, note that all points are in the same line
The idea of solving problems: first construct the convex package with the points given, and then enumerate all the points on each side to see if there are other points on the edge.
AC Code:
#include <iostream> #include <algorithm> #include <stack> #include <stdio.h> #include <cmath
> Using namespace std;
#define PI ACOs ( -1) struct point {double x,y;
Double distance (point a)//calculates two points distance {return hypot (X-A.X,Y-A.Y);
}} a[1005]; int Crossleft (point p0,point p1,point p2)//judgment left or right turn {return (p1.x-p0.x) * (P2.Y-P0.Y)-(P1.Y-P0.Y) * (p2.x-p0.x);} Boo
L CMP (point b,point C)//Polar angle Sort comparison function {int tmp = Crossleft (A[0],B,C);
if (tmp>0) return true; else if (tmp==0&&a[0].distance (b) <a[0].distance (c)) return true;
If the polar angle is the same by distance from near to far return false;
} void init (int n) {point P;
int k=0;
scanf ("%lf%lf", &a[0].x,&a[0].y); P=A[0];
P is the point for the leftmost corner for (int i=1; i<n; i++) {scanf ("%lf%lf", &a[i].x,&a[i].y); if (a[i].y<p.y| |
(a[i].y==p.y&&a[i].x<p.x))
{P=a[i];
K=i; }} A[k]=a[0];
A[0]=p;
Sort (a+1,a+n,cmp);
BOOL Pointinline (point Pi,point pj,int N) {to (int i=0; i<n; i++) {point q=a[i]; if ((!) ( (PI.X==Q.X&&PI.Y==Q.Y) | | (PJ.X==Q.X&&PJ.Y==Q.Y))) && (q.x-pi.x) * (PJ.Y-PI.Y) = = (pj.x-pi.x) * (Q.Y-PI.Y)//If dot inside segment && min (pi.x, P j.x) <= q.x && q.x <= max (pi.x, pj.x) && min (pi.y, pj.y) <= q.y && q.y &L
t;= Max (PI.Y, PJ.Y)) return false;
return true; BOOL Judge (Point *st,int top,int N) {if (top<2) return false; If all points are on a line for (int i=1; i<=top; i++) if (Pointinline (St[i-1],st[i],n)) return false;
If there is no third point in the side there is an if (Pointinline (St[top],st[0],n)) return false;
return true;
int main () {int n,t;
scanf ("%d", &t);
while (t--) {scanf ("%d", &n);
Init (N);
if (n<6)//stable convex packet minimum composition point is 6 {printf ("no\n"); Continue
Point st[1005];
int top = 1;
for (int i=0; i<2; i++) st[i]=a[i];
for (int i=2; i<n; i++) {st[++top]=a[i]; while (Top>1&&crossleft (St[top-2],st[top-1],st[top]) <=0)//If concave exists st[top-1]=st[top],--top; Out stack} printf (judge (st,top,n)?
Yes\n ":" no\n ");
}
}