program ple; type tab = array[1..100000, 1..4] of longword; var m : longword; n : longword; a : array[1..100000, 1..4] of longword; i,j,k : longword; tmp : longword; procedure qsort1(var t:tab; l,r:longword); var p,q,tmp : longword; i,j : longword; begin i:=l; j:=r; tmp:=(l+r) div 2; p:=t[tmp,1]; repeat while (t[i,1]<p) do i:=i+1; while (p<t[j,1]) do j:=j-1; if i<=j then begin tmp:=t[i,1]; t[i,1]:=t[j,1]; t[j,1]:=tmp; tmp:=t[i,2]; t[i,2]:=t[j,2]; t[j,2]:=tmp; tmp:=t[i,3]; t[i,3]:=t[j,3]; t[j,3]:=tmp; tmp:=t[i,4]; t[i,4]:=t[j,4]; t[j,4]:=tmp; i:=i+1; j:=j-1 end until i>=j; if l<j then qsort1(t,l,j); if i<r then qsort1(t,i,r) end; procedure qsort4(var t:tab; l,r:longword); var p,q,v,w,tmp : longword; i,j : longword; begin i:=l; j:=r; tmp:=(l+r) div 2; p:=t[tmp,1]; //elementy dzielace; q:=t[tmp,2]; v:=t[tmp,3]; w:=t[tmp,4]; repeat while (t[i,1]<p) or (t[i,1]=p) and ((t[i,2]<q) or (t[i,2]=q) and ((t[i,3]<v) or (t[i,3]=v) and (t[i,4]<w))) do i:=i+1; while (p<t[j,1]) or (t[j,1]=p) and ((t[j,2]>q) or (t[j,2]=q) and ((t[j,3]>v) or (t[j,3]=v) and (t[j,4]>w))) do j:=j-1; if i<=j then begin tmp:=t[i,1]; t[i,1]:=t[j,1]; t[j,1]:=tmp; tmp:=t[i,2]; t[i,2]:=t[j,2]; t[j,2]:=tmp; tmp:=t[i,3]; t[i,3]:=t[j,3]; t[j,3]:=tmp; tmp:=t[i,4]; t[i,4]:=t[j,4]; t[j,4]:=tmp; i:=i+1; j:=j-1 end until i>=j; if l<j then qsort4(t,l,j); if i<r then qsort4(t,i,r) end; begin readln(n); for j:=1 to n do readln(a[j,1],a[j,2],a[j,3],a[j,4]); if n=1 then m:=1 else begin qsort1(a,1,n); i:=1; m:=0; repeat tmp:=a[i,2]; j:=i+1; while (a[j,1]<tmp) and (j<=n) do begin if (a[j,2]>0) and (a[j,3]<a[i,4]) and (a[j,4]>a[i,3]) then begin if a[j,2]>a[i,2] then a[i,2]:=a[j,2]; if a[j,3]<a[i,3] then a[i,3]:=a[j,3]; if a[j,4]>a[i,4] then a[i,4]:=a[j,4]; a[j,1]:=0; a[j,2]:=0; j:=i+1; end else j:=j+1; end; m:=m+1; a[m,1]:=a[i,1]; a[m,2]:=a[i,2]; a[m,3]:=a[i,3]; a[m,4]:=a[i,4]; i:=i+1; while (a[i,2]=0) and (i<n) do i:=i+1; until i>n; qsort4(a,1,m); end; writeln(m); for i:=1 to m do writeln(a[i,1],' ',a[i,2],' ',a[i,3],' ',a[i,4]); end.
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 | program ple; type tab = array[1..100000, 1..4] of longword; var m : longword; n : longword; a : array[1..100000, 1..4] of longword; i,j,k : longword; tmp : longword; procedure qsort1(var t:tab; l,r:longword); var p,q,tmp : longword; i,j : longword; begin i:=l; j:=r; tmp:=(l+r) div 2; p:=t[tmp,1]; repeat while (t[i,1]<p) do i:=i+1; while (p<t[j,1]) do j:=j-1; if i<=j then begin tmp:=t[i,1]; t[i,1]:=t[j,1]; t[j,1]:=tmp; tmp:=t[i,2]; t[i,2]:=t[j,2]; t[j,2]:=tmp; tmp:=t[i,3]; t[i,3]:=t[j,3]; t[j,3]:=tmp; tmp:=t[i,4]; t[i,4]:=t[j,4]; t[j,4]:=tmp; i:=i+1; j:=j-1 end until i>=j; if l<j then qsort1(t,l,j); if i<r then qsort1(t,i,r) end; procedure qsort4(var t:tab; l,r:longword); var p,q,v,w,tmp : longword; i,j : longword; begin i:=l; j:=r; tmp:=(l+r) div 2; p:=t[tmp,1]; //elementy dzielace; q:=t[tmp,2]; v:=t[tmp,3]; w:=t[tmp,4]; repeat while (t[i,1]<p) or (t[i,1]=p) and ((t[i,2]<q) or (t[i,2]=q) and ((t[i,3]<v) or (t[i,3]=v) and (t[i,4]<w))) do i:=i+1; while (p<t[j,1]) or (t[j,1]=p) and ((t[j,2]>q) or (t[j,2]=q) and ((t[j,3]>v) or (t[j,3]=v) and (t[j,4]>w))) do j:=j-1; if i<=j then begin tmp:=t[i,1]; t[i,1]:=t[j,1]; t[j,1]:=tmp; tmp:=t[i,2]; t[i,2]:=t[j,2]; t[j,2]:=tmp; tmp:=t[i,3]; t[i,3]:=t[j,3]; t[j,3]:=tmp; tmp:=t[i,4]; t[i,4]:=t[j,4]; t[j,4]:=tmp; i:=i+1; j:=j-1 end until i>=j; if l<j then qsort4(t,l,j); if i<r then qsort4(t,i,r) end; begin readln(n); for j:=1 to n do readln(a[j,1],a[j,2],a[j,3],a[j,4]); if n=1 then m:=1 else begin qsort1(a,1,n); i:=1; m:=0; repeat tmp:=a[i,2]; j:=i+1; while (a[j,1]<tmp) and (j<=n) do begin if (a[j,2]>0) and (a[j,3]<a[i,4]) and (a[j,4]>a[i,3]) then begin if a[j,2]>a[i,2] then a[i,2]:=a[j,2]; if a[j,3]<a[i,3] then a[i,3]:=a[j,3]; if a[j,4]>a[i,4] then a[i,4]:=a[j,4]; a[j,1]:=0; a[j,2]:=0; j:=i+1; end else j:=j+1; end; m:=m+1; a[m,1]:=a[i,1]; a[m,2]:=a[i,2]; a[m,3]:=a[i,3]; a[m,4]:=a[i,4]; i:=i+1; while (a[i,2]=0) and (i<n) do i:=i+1; until i>n; qsort4(a,1,m); end; writeln(m); for i:=1 to m do writeln(a[i,1],' ',a[i,2],' ',a[i,3],' ',a[i,4]); end. |