#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
int jest[100005];
int xx1[100005];
int xx2[100005];
int yy1[100005];
int yy2[100005];
vector< pair<pair<int,int>, pair<int, int> > > wyn;
vector<int> dobre;
int main()
{
ios_base::sync_with_stdio(0);
int n, zmiany, XX1, XX2, YY1, YY2;
cin >> n;
for(int i=1; i<=n; i++)
{
cin >> xx1[i] >> xx2[i] >> yy1[i] >> yy2[i];
}
zmiany=1;
while(zmiany!=0)
{
dobre.clear();
zmiany=0;
for(int i=1; i<=n; i++)
{
if(xx1[i]!=xx2[i]) {jest[i]=1; dobre.push_back(i);}
else jest[i]=0;
}
for(int a=0; a<dobre.size(); a++)
{
int i=dobre[a];
if(jest[i]==0) continue;
for(int b=a+1; b<dobre.size(); b++)
{
int j=dobre[b];
if(jest[j]==0) continue;
YY1=max(yy1[i],yy1[j]);
YY2=min(yy2[i],yy2[j]);
XX1=max(xx1[i],xx1[j]);
XX2=min(xx2[i],xx2[j]);
if(YY1<YY2 && XX1<XX2)
{
zmiany++;
yy1[i]=min(yy1[i],yy1[j]);
yy2[i]=max(yy2[i],yy2[j]);
xx1[i]=min(xx1[i],xx1[j]);
xx2[i]=max(xx2[i],xx2[j]);
yy1[j]=0; yy2[j]=0; xx1[j]=0; xx2[j]=0;
jest[j]=0;
}
}
}
}
for(int i=1; i<=n; i++)
{
if(xx1[i]!=xx2[i])
{
wyn.push_back(make_pair( make_pair(xx1[i], xx2[i]), make_pair(yy1[i],yy2[i])) ) ;
}
}
sort(wyn.begin(), wyn.end());
cout << wyn.size() << endl;
for(int i=0; i<wyn.size(); i++)
{
cout << wyn[i].first.first << " " << wyn[i].first.second << " " << wyn[i].second.first << " " << wyn[i].second.second << endl;
}
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 | #include<cstdio> #include<iostream> #include<algorithm> #include<vector> #include<queue> using namespace std; int jest[100005]; int xx1[100005]; int xx2[100005]; int yy1[100005]; int yy2[100005]; vector< pair<pair<int,int>, pair<int, int> > > wyn; vector<int> dobre; int main() { ios_base::sync_with_stdio(0); int n, zmiany, XX1, XX2, YY1, YY2; cin >> n; for(int i=1; i<=n; i++) { cin >> xx1[i] >> xx2[i] >> yy1[i] >> yy2[i]; } zmiany=1; while(zmiany!=0) { dobre.clear(); zmiany=0; for(int i=1; i<=n; i++) { if(xx1[i]!=xx2[i]) {jest[i]=1; dobre.push_back(i);} else jest[i]=0; } for(int a=0; a<dobre.size(); a++) { int i=dobre[a]; if(jest[i]==0) continue; for(int b=a+1; b<dobre.size(); b++) { int j=dobre[b]; if(jest[j]==0) continue; YY1=max(yy1[i],yy1[j]); YY2=min(yy2[i],yy2[j]); XX1=max(xx1[i],xx1[j]); XX2=min(xx2[i],xx2[j]); if(YY1<YY2 && XX1<XX2) { zmiany++; yy1[i]=min(yy1[i],yy1[j]); yy2[i]=max(yy2[i],yy2[j]); xx1[i]=min(xx1[i],xx1[j]); xx2[i]=max(xx2[i],xx2[j]); yy1[j]=0; yy2[j]=0; xx1[j]=0; xx2[j]=0; jest[j]=0; } } } } for(int i=1; i<=n; i++) { if(xx1[i]!=xx2[i]) { wyn.push_back(make_pair( make_pair(xx1[i], xx2[i]), make_pair(yy1[i],yy2[i])) ) ; } } sort(wyn.begin(), wyn.end()); cout << wyn.size() << endl; for(int i=0; i<wyn.size(); i++) { cout << wyn[i].first.first << " " << wyn[i].first.second << " " << wyn[i].second.first << " " << wyn[i].second.second << endl; } return 0; } |
English