记录编号 383333 评测结果 AAAAAAAAAAA
题目名称 [POI 1998] 相交的矩形 最终得分 100
用户昵称 GravatarkZime 是否通过 通过
代码语言 C++ 运行时间 0.154 s
提交时间 2017-03-15 19:14:36 内存使用 2.51 MiB
显示代码纯文本
/*kZime*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#define MAXN 7023
using namespace std;
inline int read() {
	int k = 0, f = 1; char c = getchar();
	for(; !isdigit(c); c = getchar())if(c == '-') f = -1;
	for(; isdigit(c); c = getchar()) k = k * 10 + c - '0';
	return k * f;
}
/*-----------------------------------------------------------------------------*/
int n, u[MAXN]; 

struct land {
	int x1, y1;
	int x2, y2;
	
	void in() {
		x1 = read();
		y1 = read();
		x2 = read();
		y2 = read();
	}
}l[MAXN];
bool p(land a, land b) {
	if(a.x2 < b.x1 || a.x1 > b.x2 || a.y1 > b.y2 || a.y2 < b.y1) return 0;
	else{
		if(a.x2 == b.x1) {
			if(a.y2 <= b.y1 || a.y1 >= b.y2) return 0;
			else return 1;
		}
		if(a.x1 == b.x2) {
			if(b.y2 <= a.y1 || b.y1 >= a.y2) return 0;
			else return 1;
		}
	}
	return 1;
}

int getf(int x) {
	if(x == u[x]) return x;
	else {
		u[x] = getf(u[x]);
	}
	return u[x];
}

bool Union(int a, int b) {
	int fa = getf(a);
	int fb = getf(b);
	if(u[fa] != u[fb]) {
		u[fb] = fa;
		return 1;
	}else return 0;
}

int AC() {
#ifndef MYLAB
	freopen("pro.in", "r", stdin);
	freopen("pro.out", "w", stdout);
#else
	freopen("in.txt", "r", stdin);
#endif
	n = read();
	
	for(int i = 1; i <= n; i++) {
		l[i].in();
		u[i] = i;
	}
	
	int ans = n;
	
	for(int i = 1; i <= n; i++) {
		for(int j = i + 1; j <= n; j++) {
			if(p(l[i], l[j]) && Union(i, j)) {
				ans--;
				if (ans == 1) {
					printf("1");
					return 0;
				}
			}
		}
	}
	
	printf("%d", ans);





	return 0;
}
int HA = AC();
int main(){;}