/* Arek Wróbel - skater
*
* Zadanie: Plemiona
* Konkurs: PA2014, runda 5B
*/
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define REP(I, N) for(int I=0; I<(N); ++I)
#define FOR(I, M, N) for(int I=(M); I<=(N); ++I)
#define FORD(I, M, N) for(int I=(M); I>=(N); --I)
#define FOREACH(IT, CON) for(__typeof(CON.begin()) IT=CON.begin(); IT!=CON.end(); ++IT)
#define ST first
#define ND second
#define MP make_pair
#define PB push_back
const int INF=1000000000;
const LL INFLL=1000000000000000000LL;
typedef pair<PII, PII> Rect;
vector<Rect> t;
inline bool przeciecie(Rect a, Rect b) {
if (a.ST.ND <= b.ST.ST) return false;
if (b.ST.ND <= a.ST.ST) return false;
if (a.ND.ND <= b.ND.ST) return false;
if (b.ND.ND <= a.ND.ST) return false;
return true;
}
bool make() { // czy coś zmieniono
bool wy = false;
REP(i, (int)t.size()) {
for (int j = i+1; j<(int)t.size(); ++j) {
if (przeciecie(t[i], t[j])) {
wy = true;
t[i].ST.ST = min(t[i].ST.ST, t[j].ST.ST);
t[i].ST.ND = max(t[i].ST.ND, t[j].ST.ND);
t[i].ND.ST = min(t[i].ND.ST, t[j].ND.ST);
t[i].ND.ND = max(t[i].ND.ND, t[j].ND.ND);
swap(t[j], t[t.size()-1]);
t.pop_back();
--j;
}
}
}
return wy;
}
int main()
{
//wej
int n;
scanf("%d", &n);
REP(i, n) {
int x1, x2, y1, y2;
scanf("%d%d%d%d", &x1, &x2, &y1, &y2);
t.PB(MP(MP(x1, x2), MP(y1, y2)));
}
//prog
while (make()) ;
sort(t.begin(), t.end());
//wyj
printf("%d\n", (int)t.size());
REP(i, (int)t.size())
printf("%d %d %d %d\n", t[i].ST.ST, t[i].ST.ND, t[i].ND.ST, t[i].ND.ND);
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 | /* Arek Wróbel - skater * * Zadanie: Plemiona * Konkurs: PA2014, runda 5B */ #include <cstdio> #include <algorithm> #include <cmath> #include <vector> using namespace std; typedef long long LL; typedef pair<int, int> PII; typedef vector<int> VI; #define REP(I, N) for(int I=0; I<(N); ++I) #define FOR(I, M, N) for(int I=(M); I<=(N); ++I) #define FORD(I, M, N) for(int I=(M); I>=(N); --I) #define FOREACH(IT, CON) for(__typeof(CON.begin()) IT=CON.begin(); IT!=CON.end(); ++IT) #define ST first #define ND second #define MP make_pair #define PB push_back const int INF=1000000000; const LL INFLL=1000000000000000000LL; typedef pair<PII, PII> Rect; vector<Rect> t; inline bool przeciecie(Rect a, Rect b) { if (a.ST.ND <= b.ST.ST) return false; if (b.ST.ND <= a.ST.ST) return false; if (a.ND.ND <= b.ND.ST) return false; if (b.ND.ND <= a.ND.ST) return false; return true; } bool make() { // czy coś zmieniono bool wy = false; REP(i, (int)t.size()) { for (int j = i+1; j<(int)t.size(); ++j) { if (przeciecie(t[i], t[j])) { wy = true; t[i].ST.ST = min(t[i].ST.ST, t[j].ST.ST); t[i].ST.ND = max(t[i].ST.ND, t[j].ST.ND); t[i].ND.ST = min(t[i].ND.ST, t[j].ND.ST); t[i].ND.ND = max(t[i].ND.ND, t[j].ND.ND); swap(t[j], t[t.size()-1]); t.pop_back(); --j; } } } return wy; } int main() { //wej int n; scanf("%d", &n); REP(i, n) { int x1, x2, y1, y2; scanf("%d%d%d%d", &x1, &x2, &y1, &y2); t.PB(MP(MP(x1, x2), MP(y1, y2))); } //prog while (make()) ; sort(t.begin(), t.end()); //wyj printf("%d\n", (int)t.size()); REP(i, (int)t.size()) printf("%d %d %d %d\n", t[i].ST.ST, t[i].ST.ND, t[i].ND.ST, t[i].ND.ND); return 0; } |
English