Usaco2011open Bronze 3lines

Source: Internet
Author: User
Ideas
There are two cases of compliance with FJ: three straight lines parallel or two straight lines parallel and perpendicular to a straight line. As for the problem of the vertical and horizontal, you can reverse the cow's coordinates into the same way.

Three Parallel lines:

Record the horizontal axis of all points, if the number of different horizontal axis is less than or equal to 3, then meet the conditions. Two parallel perpendicular to a straight line:
Put all the ordinate and the number of them, also note all the appearance of the ordinate number, and then in accordance with the horizontal order, and then enumerate a horizontal axis A, indicating that the line x=a and the other two horizontal lines perpendicular, and then the line of all the ordinate CNT--, then see the number of vertical axis, if <=2, the explanation is established .

The standard process is much more refined than mine, so I'll put it on the mark ...

#include <cstdio> #include <cstring> #include <map> #include <algorithm> using namespace std;
const int MAXN = 1001000;
Pair<int,int> LIS[MAXN];
Map<int, int> cou;
int distinct;
int n;

VOID Inc (int x) {if (cou[x] = = 0) {distinct++;//different ordinate numbers} cou[x] = cou[x] + 1;}
	void Dec (int x) {cou[x] = cou[x]-1;
if (cou[x] = = 0) distinct--;
	} int Moo () {sort (lis, Lis + N);//Sort, place the same horizontal axis together distinct = 0;
	Cou.clear ();
	for (int i = 0; i < n; ++i) {Inc (Lis[i].second);
	} if (distinct <= 3) return 1;//three parallel int i = 0, i1 = 0;
		while (I < n) {while (I1 < n && lis[i].first = = Lis[i1].first) i1++;
		for (int i2 = i; i2 < i1; ++i2) Dec (lis[i2].second);//delete all ordinate if on a vertical line (distinct <= 2) return 1;
		for (int i2 = i; i2 < I1; ++i2) Inc (Lis[i2].second);
	i = I1;
} return 0;
	} int main () {scanf ("%d", &n);
	for (int i = 0; i < n; ++i) scanf ("%d%d", &lis[i].first, &lis[i].second);
	if (Moo ()) {puts ("1");
}	else {for (int i = 0; i < n; ++i) {swap (Lis[i].first, lis[i].second);//Invert coordinates} if (Moo ()) puts ("1");
	Else puts ("0");
} return 0;
 }


Related Keywords:

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.