#include #include #include #include #include #include #include #include #include #include using namespace std; struct Rect { int l, b, r, t; bool PointIn(int x, int y) { return (l <= x && x <= r && b <= y && y <= t); } }; bool Intersect(Rect& r1, Rect& r2) { if(r1.PointIn(r2.l, r2.b) || r1.PointIn(r2.l, r2.t) || r1.PointIn(r2.r, r2.b) || r1.PointIn(r2.r, r2.t) || r2.PointIn(r1.l, r1.b) || r2.PointIn(r1.l, r1.t) || r2.PointIn(r1.r, r1.b) || r2.PointIn(r1.r, r1.t)) return true; if((r1.l < r2.l && r1.r > r2.r) || (r1.l > r2.l && r1.r < r2.r)) { if((r1.b< r2.b && r1.t > r2.t) || (r1.b > r2.b && r1.t < r2.t)) return true; } return false; } Rect input[200]; int color[200]; int main() { ifstream cin("rect.txt"); int M; cin >> M; for(int I = 0; I < M; ++I) { int n; cin >> n; for(int i = 0; i < n; ++i) { cin >> input[i].l >> input[i].b >> input[i].r >> input[i].t; } int cnt = 0; memset(color, 0, sizeof(color)); for(int i = 0; i < n; ++i) { if(color[i] != 0) continue; color[i] = ++cnt; int c = color[i]; set up; up.insert(i); while(!up.empty()) { int cur = *up.begin(); up.erase(up.begin()); for(int j = 0; j < n; ++j) { if(color[j] == 0 && Intersect(input[cur], input[j])) { color[j] = c; up.insert(j); } } } } cout << cnt << endl; } }