//Tadrion #include <cstdio> #include <vector> #include <iostream> #include <deque> #include <map> #include <set> #include <string> #include <cstring> #include <cstdlib> #include <cmath> #include <queue> #include <stack> #include <algorithm> #include <utility> using namespace std; #define MAX(a,b) ((a) > (b) ? (a) : (b)) #define MIN(a,b) ((a) < (b) ? (a) : (b)) #define CLEAR(x) (memset(x,0,sizeof(x))) #define SZ(x) ((int)(x).size()) #define ALL(x) (x).begin(),(x).end() #define VAR(v, n) __typeof(n) v = (n) #define FOR(x, b, e) for(int x = b; x <= (e); ++x) #define FORD(x, b, e) for(int x = b; x >= (e); --x) #define REP(x, n) for(int x = 0; x < (n); ++x) #define FOREACH(i, c) for(VAR(i,(c).begin()); i != (c).end(); ++i) #define DBG(v) cout<<#v<<" = "<<v<<endl; #define IN(x,y) ((y).find(x)!=(y).end()) #define ST first #define ND second #define PB push_back #define PF push_front #define MP make_pair typedef long long int LL; typedef pair<int,int> PII; typedef vector<int> VI; int n; void do1() { vector<pair<PII,PII> > v,v2; vector<pair<PII,PII> > res; int a,b,c,d; FOR(i,1,n) { scanf("%d %d %d %d",&a,&b,&c,&d); v.PB(MP(MP(a,c),MP(b,d))); } int zm = 1; while(zm) { zm=0; REP(i,SZ(v)) for(int j = i+1; j < SZ(v); j++) { if(v[i].ST.ST <= v[j].ST.ST && v[i].ST.ND <= v[j].ST.ND && v[i].ND.ST >= v[j].ST.ST && v[i].ND.ND >= v[j].ST.ND) { pair<PII,PII> p = MP(MP(v[i].ST.ST,v[i].ST.ND),MP(MAX(v[i].ND.ST,v[j].ND.ST),MAX(v[i].ND.ND,v[j].ND.ND))); v[i] = p; v[j] = v.back(); v.pop_back(); zm=1; j--; } } } REP(i,SZ(v)) res.PB(MP(MP(v[i].ST.ST,v[i].ND.ST),MP(v[i].ST.ND,v[i].ND.ND))); sort(res.begin(),res.end()); printf("%d\n",SZ(res)); REP(i,SZ(res)) printf("%d %d %d %d\n",res[i].ST.ST,res[i].ST.ND,res[i].ND.ST,res[i].ND.ND); } void do2() { } int main() { scanf("%d",&n); if(n <= 100000) do1(); else do2(); 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 | //Tadrion #include <cstdio> #include <vector> #include <iostream> #include <deque> #include <map> #include <set> #include <string> #include <cstring> #include <cstdlib> #include <cmath> #include <queue> #include <stack> #include <algorithm> #include <utility> using namespace std; #define MAX(a,b) ((a) > (b) ? (a) : (b)) #define MIN(a,b) ((a) < (b) ? (a) : (b)) #define CLEAR(x) (memset(x,0,sizeof(x))) #define SZ(x) ((int)(x).size()) #define ALL(x) (x).begin(),(x).end() #define VAR(v, n) __typeof(n) v = (n) #define FOR(x, b, e) for(int x = b; x <= (e); ++x) #define FORD(x, b, e) for(int x = b; x >= (e); --x) #define REP(x, n) for(int x = 0; x < (n); ++x) #define FOREACH(i, c) for(VAR(i,(c).begin()); i != (c).end(); ++i) #define DBG(v) cout<<#v<<" = "<<v<<endl; #define IN(x,y) ((y).find(x)!=(y).end()) #define ST first #define ND second #define PB push_back #define PF push_front #define MP make_pair typedef long long int LL; typedef pair<int,int> PII; typedef vector<int> VI; int n; void do1() { vector<pair<PII,PII> > v,v2; vector<pair<PII,PII> > res; int a,b,c,d; FOR(i,1,n) { scanf("%d %d %d %d",&a,&b,&c,&d); v.PB(MP(MP(a,c),MP(b,d))); } int zm = 1; while(zm) { zm=0; REP(i,SZ(v)) for(int j = i+1; j < SZ(v); j++) { if(v[i].ST.ST <= v[j].ST.ST && v[i].ST.ND <= v[j].ST.ND && v[i].ND.ST >= v[j].ST.ST && v[i].ND.ND >= v[j].ST.ND) { pair<PII,PII> p = MP(MP(v[i].ST.ST,v[i].ST.ND),MP(MAX(v[i].ND.ST,v[j].ND.ST),MAX(v[i].ND.ND,v[j].ND.ND))); v[i] = p; v[j] = v.back(); v.pop_back(); zm=1; j--; } } } REP(i,SZ(v)) res.PB(MP(MP(v[i].ST.ST,v[i].ND.ST),MP(v[i].ST.ND,v[i].ND.ND))); sort(res.begin(),res.end()); printf("%d\n",SZ(res)); REP(i,SZ(res)) printf("%d %d %d %d\n",res[i].ST.ST,res[i].ST.ND,res[i].ND.ST,res[i].ND.ND); } void do2() { } int main() { scanf("%d",&n); if(n <= 100000) do1(); else do2(); return 0; } |