#include <list> #include <cstdlib> #include <algorithm> #include <vector> #include <cstdio> #define max(a,b) (((a)>(b))?(a):(b)) #define min(a,b) (((a)<(b))?(a):(b)) using namespace std; vector<int> IAx; vector<int> IAy; vector<int> IBx; vector<int> IBy; vector<int> Ax; vector<int> Ay; vector<int> Bx; vector<int> By; vector<int> P; list<int> abcd; struct fajne { bool operator() (int i,int j) { return Ax[i] < Ax[j] || Ax[i] == Ax[j] && Bx[i] < Bx[j] || Ax[i] == Ax[j] && Bx[i] == Bx[j] && Ay[i] < Ay[j] || Ax[i] == Ax[j] && Bx[i] == Bx[j] && Ay[i] == Ay[j] && By[i] < By[j] ; } } cmp; struct foo { bool operator() (int i,int j) { return IAx[i] < IAx[j] || IAx[i] == IAx[j] && IBx[i] < IBx[j] || IAx[i] == IAx[j] && IBx[i] == IBx[j] && IAy[i] < IAy[j] || IAx[i] == IAx[j] && IBx[i] == IBx[j] && IAy[i] == IAy[j] && IBy[i] < IBy[j] ; } } bar; int N; int a,b,c,d; int main() { scanf("%d",&N); for (int i = 0; i<N;++i) { scanf("%d %d %d %d",&a,&b,&c,&d); IAx.push_back(a); IBx.push_back(b); IAy.push_back(c); IBy.push_back(d); P.push_back(i); } sort(P.begin(),P.end(),bar); for (int i =0; i< N;++i) { a = IAx[P[i]]; b = IBx[P[i]]; c = IAy[P[i]]; d = IBy[P[i]]; int jeszcze = 1; while (jeszcze) { jeszcze = 0; for(list<int>::iterator it = abcd.begin(); it != abcd.end(); ++it) //FOREACH(it,abcd) { int pos = *it; //printf("pos %d",pos); if (!( Ax[pos] >= b || Bx[pos] <= a || Ay[pos] >= d || By[pos] <= c )) { a = min(a,Ax[pos]); b = max(b,Bx[pos]); c = min(c,Ay[pos]); d = max(d,By[pos]); jeszcze = 1; abcd.erase(it); break; } } //printf("jeszcze %d\n",jeszcze); } abcd.push_front( Ax.size() ); Ax.push_back(a); Bx.push_back(b); Ay.push_back(c); By.push_back(d); } vector<int> res(abcd.begin(), abcd.end()); sort(res.begin(),res.end(), cmp); printf("%d\n",res.size()); for (int i = 0 ; i<res.size();++i) { printf("%d %d %d %d\n",Ax[res[i]],Bx[res[i]],Ay[res[i]],By[res[i]]); } 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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | #include <list> #include <cstdlib> #include <algorithm> #include <vector> #include <cstdio> #define max(a,b) (((a)>(b))?(a):(b)) #define min(a,b) (((a)<(b))?(a):(b)) using namespace std; vector<int> IAx; vector<int> IAy; vector<int> IBx; vector<int> IBy; vector<int> Ax; vector<int> Ay; vector<int> Bx; vector<int> By; vector<int> P; list<int> abcd; struct fajne { bool operator() (int i,int j) { return Ax[i] < Ax[j] || Ax[i] == Ax[j] && Bx[i] < Bx[j] || Ax[i] == Ax[j] && Bx[i] == Bx[j] && Ay[i] < Ay[j] || Ax[i] == Ax[j] && Bx[i] == Bx[j] && Ay[i] == Ay[j] && By[i] < By[j] ; } } cmp; struct foo { bool operator() (int i,int j) { return IAx[i] < IAx[j] || IAx[i] == IAx[j] && IBx[i] < IBx[j] || IAx[i] == IAx[j] && IBx[i] == IBx[j] && IAy[i] < IAy[j] || IAx[i] == IAx[j] && IBx[i] == IBx[j] && IAy[i] == IAy[j] && IBy[i] < IBy[j] ; } } bar; int N; int a,b,c,d; int main() { scanf("%d",&N); for (int i = 0; i<N;++i) { scanf("%d %d %d %d",&a,&b,&c,&d); IAx.push_back(a); IBx.push_back(b); IAy.push_back(c); IBy.push_back(d); P.push_back(i); } sort(P.begin(),P.end(),bar); for (int i =0; i< N;++i) { a = IAx[P[i]]; b = IBx[P[i]]; c = IAy[P[i]]; d = IBy[P[i]]; int jeszcze = 1; while (jeszcze) { jeszcze = 0; for(list<int>::iterator it = abcd.begin(); it != abcd.end(); ++it) //FOREACH(it,abcd) { int pos = *it; //printf("pos %d",pos); if (!( Ax[pos] >= b || Bx[pos] <= a || Ay[pos] >= d || By[pos] <= c )) { a = min(a,Ax[pos]); b = max(b,Bx[pos]); c = min(c,Ay[pos]); d = max(d,By[pos]); jeszcze = 1; abcd.erase(it); break; } } //printf("jeszcze %d\n",jeszcze); } abcd.push_front( Ax.size() ); Ax.push_back(a); Bx.push_back(b); Ay.push_back(c); By.push_back(d); } vector<int> res(abcd.begin(), abcd.end()); sort(res.begin(),res.end(), cmp); printf("%d\n",res.size()); for (int i = 0 ; i<res.size();++i) { printf("%d %d %d %d\n",Ax[res[i]],Bx[res[i]],Ay[res[i]],By[res[i]]); } return 0; } |