#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
int prostokaty[300001][4];
vector<int> tab[100001];
int czy[400001];
int main(){
int n;
scanf("%d", &n);
for(int i=0; i<n; i++){
int x;
for(int j=1; j<=4; j++){
scanf("%d", &x);
tab[i].push_back(x);
}
tab[i].clear();
}
sort(tab, tab+n);
for(int i=0; i<n; i++){
for(int j=0; j<4; j++)
prostokaty[i][j]=tab[i][j];
}
for(int i=0; i<n; i++)
if(czy[i]==0) {
int x1=prostokaty[i][0];
int x2=prostokaty[i][1];
int y1=prostokaty[i][2];
int y2=prostokaty[i][3];
for(int j=0; j<n; j++)
if(j!=i && czy[j]==0){
int x11=max(x1,prostokaty[j][0]);
int x22=min(x2, prostokaty[j][1]);
int y11=max(y1, prostokaty[j][2]);
int y22=min(y2, prostokaty[j][3]);
if(x22>x11 && y22>y11){
czy[i]=1;
czy[j]=1;
x1=min(x1, prostokaty[j][0]);
x2=max(x2, prostokaty[j][1]);
y1=min(y1, prostokaty[j][2]);
y2=max(y2, prostokaty[j][3]);
}
}
if(czy[i]==1){
n++;
prostokaty[n-1][0]=x1;
prostokaty[n-1][1]=x2;
prostokaty[n-1][2]=y1;
prostokaty[n-1][3]=y2;
}
}
int m=-1;
for(int i=0; i<n; i++){
if(czy[i]==0){
m++;
for(int j=0; j<4; j++)
tab[m].push_back(prostokaty[i][j]);
}
}
m++;
sort(tab, tab+m);
printf("%d\n", m);
for(int i=0; i<m; i++){
for(int j=0; j<4; j++)
printf("%d ", tab[i][j]);
printf("\n");
}
}
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 | #include<cstdio> #include<vector> #include<algorithm> using namespace std; int prostokaty[300001][4]; vector<int> tab[100001]; int czy[400001]; int main(){ int n; scanf("%d", &n); for(int i=0; i<n; i++){ int x; for(int j=1; j<=4; j++){ scanf("%d", &x); tab[i].push_back(x); } tab[i].clear(); } sort(tab, tab+n); for(int i=0; i<n; i++){ for(int j=0; j<4; j++) prostokaty[i][j]=tab[i][j]; } for(int i=0; i<n; i++) if(czy[i]==0) { int x1=prostokaty[i][0]; int x2=prostokaty[i][1]; int y1=prostokaty[i][2]; int y2=prostokaty[i][3]; for(int j=0; j<n; j++) if(j!=i && czy[j]==0){ int x11=max(x1,prostokaty[j][0]); int x22=min(x2, prostokaty[j][1]); int y11=max(y1, prostokaty[j][2]); int y22=min(y2, prostokaty[j][3]); if(x22>x11 && y22>y11){ czy[i]=1; czy[j]=1; x1=min(x1, prostokaty[j][0]); x2=max(x2, prostokaty[j][1]); y1=min(y1, prostokaty[j][2]); y2=max(y2, prostokaty[j][3]); } } if(czy[i]==1){ n++; prostokaty[n-1][0]=x1; prostokaty[n-1][1]=x2; prostokaty[n-1][2]=y1; prostokaty[n-1][3]=y2; } } int m=-1; for(int i=0; i<n; i++){ if(czy[i]==0){ m++; for(int j=0; j<4; j++) tab[m].push_back(prostokaty[i][j]); } } m++; sort(tab, tab+m); printf("%d\n", m); for(int i=0; i<m; i++){ for(int j=0; j<4; j++) printf("%d ", tab[i][j]); printf("\n"); } } |
English