#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
struct prostokat
{
int ax;
int ay;
int bx;
int by;
};
bool przeciecie(prostokat a, prostokat b)
{
if(a.ax <= b.bx && a.ay <= b.by)
{
if(b.ax < a.bx && b.ay < a.by) return true;
}
else
{
if(a.ax < b.bx && a.ay < b.by) return true;
}
return false;
}
bool cmp(prostokat a, prostokat b)
{
if(a.ax == b.ax && a.bx == b.bx && a.ay == b.ay) return a.by < b.by;
else if(a.ax == b.ax && a.bx == b.bx) return a.ay < b.ay;
else if(a.ax == b.ax) return a.bx < b.bx;
else return a.ax < b.ax;
}
int main()
{
ios_base::sync_with_stdio(0);
int n;
cin >> n;
vector <prostokat> t(n);
for(int i = 0; i < n; ++i)
{
cin >> t[i].ax >> t[i].bx >> t[i].ay >> t[i].by;
}
int stop = 1;
while(stop)
{
stop = 0;
for(int i = 0; i < n; ++i)
{
for(int j = i + 1; j < n; ++j)
{
if(przeciecie(t[i], t[j]))
{
t[i].ax = min(t[i].ax, t[j].ax);
t[i].ay = min(t[i].ay, t[j].ay);
t[i].bx = max(t[i].bx, t[j].bx);
t[i].by = max(t[i].by, t[j].by);
t[j].ax = t[j].ay = t[j].bx = t[j].by = -1;
stop = 1;
}
}
}
}
sort(t.begin(), t.end(), cmp);
bool show = 0;
for(int i = 0; i < n; ++i)
{
if(t[i].ax > -1 && !show)
{
cout << n - i << '\n';
show = 1;
}
if(show) cout << t[i].ax << ' ' << t[i].bx << ' ' << t[i].ay << ' ' << t[i].by << '\n';
}
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | #include <iostream> #include <cstdio> #include <vector> #include <algorithm> using namespace std; struct prostokat { int ax; int ay; int bx; int by; }; bool przeciecie(prostokat a, prostokat b) { if(a.ax <= b.bx && a.ay <= b.by) { if(b.ax < a.bx && b.ay < a.by) return true; } else { if(a.ax < b.bx && a.ay < b.by) return true; } return false; } bool cmp(prostokat a, prostokat b) { if(a.ax == b.ax && a.bx == b.bx && a.ay == b.ay) return a.by < b.by; else if(a.ax == b.ax && a.bx == b.bx) return a.ay < b.ay; else if(a.ax == b.ax) return a.bx < b.bx; else return a.ax < b.ax; } int main() { ios_base::sync_with_stdio(0); int n; cin >> n; vector <prostokat> t(n); for(int i = 0; i < n; ++i) { cin >> t[i].ax >> t[i].bx >> t[i].ay >> t[i].by; } int stop = 1; while(stop) { stop = 0; for(int i = 0; i < n; ++i) { for(int j = i + 1; j < n; ++j) { if(przeciecie(t[i], t[j])) { t[i].ax = min(t[i].ax, t[j].ax); t[i].ay = min(t[i].ay, t[j].ay); t[i].bx = max(t[i].bx, t[j].bx); t[i].by = max(t[i].by, t[j].by); t[j].ax = t[j].ay = t[j].bx = t[j].by = -1; stop = 1; } } } } sort(t.begin(), t.end(), cmp); bool show = 0; for(int i = 0; i < n; ++i) { if(t[i].ax > -1 && !show) { cout << n - i << '\n'; show = 1; } if(show) cout << t[i].ax << ' ' << t[i].bx << ' ' << t[i].ay << ' ' << t[i].by << '\n'; } return 0; } |
English