NYOJ78 Circle Pool (convex hull template)

Source: Internet
Author: User
Tags bool min
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&LT;=M&LT;=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&AMP;&AMP;A.Y&LT;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&&amp ;
		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",&AMP;HULL[I].X,&AMP;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;  }

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.