Lap PoolTime limit: Ms | Memory limit: 65535 KB Difficulty: 4 Description There is a pasture with a lot of water supply, and now the owner of the ranch wants to use a fence to circle the water supply, to prevent their livestock from drinking, and each pool has its own coordinates. Now you need to write a program that uses the shortest fence to circle these water supply units. (Fence is large enough and variable in length) enter N for the first line, representing the test data in N Group (1<=n<=10)
The second line is M, which represents a total of M water supply units (3<=M<=100) for this group of test data.
The next M-line represents the output output of each fence through the coordinate points of each water supply unit, and the output from small to large x-axis coordinates, if the x-axis coordinate value is the same, then Yasuteru y-coordinate value from small to large output sample input
1
4
0 0
1 1
2 3
3 0
Sample output
0 0
2 3
3 0
/* For convex hull template, see Half a day, refueling ...
TIME:2014-10-17 22:41 */#include <cstdio> #include <cstring> #include <algorithm> using namespace std; #define MAX. struct convex{int x, y;}
Res[max],hull[max];
BOOL CMP (convex A,convex b) {if (a.x<b.x) return true;
else if (A.X==B.X&&A.Y<B.Y) return true;
return false; } bool Judge (convex A,convex B,convex c) {return (c.x-a.x) * (C.Y-B.Y)-(c.x-b.x) * (C.Y-A.Y) <0;//ac Fork by BC less than 0 or greater than 0//influence first request
is the upper half shell or the lower half Shell} int convexhull (int len) {sort (hull,hull+len,cmp);
int m=0;
for (int i=0;i<len;i++) {while (M>1&&judge (Res[m-2],res[m-1],hull[i]))//non-conforming returns true m--;
Res[m++]=hull[i]; The M after int temp=m;//cannot be less than this value for (int i=len-2;i>=0;i--) {//Because starting from 0, so when the upper half is scanned, the second from the bottom of the first is Len-2 on the line while (M>temp&& ;
Judge (Res[m-2],res[m-1],hull[i]) m--;
Res[m++]=hull[i];
} if (len>1) m--;//because the first point two times return m;
} int main () {int t,n;
scanf ("%d", &t);
while (t--) {scanf ("%d", &n); for (int i=0;i<n;i++) scanf ("%d%d",&HULL[I].X,&HULL[I].Y);
int L=convexhull (N);
Sort (res,res+l,cmp);
for (int i=0;i<l;i++) {printf ("%d%d\n", res[i].x,res[i].y);
}} return 0; }