ENG  RUS Timus Online Judge
Online Judge
Problems
Authors
Online contests
Site news
Webboard
Problem set
Submit solution
Judge status
Guide
Register
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

## Discussion of Problem 1112. Cover

Any wrongs here in my program?
Posted by BYF 7 Nov 2002 07:57
Program P1112;
Type
Coor=Record
X,Y:Integer;
End;
Var
N,I,J,Last,Which:Integer;
Num,Left:Array[1..100] Of Coor;

procedure Sort(l, r: longint);
var
i, j, x: longint;
Y:Coor;
begin
i := l; j := r; x := Num[(l+r) DIV 2].Y;
repeat
while Num[i].Y < x do i := i + 1;
while x < Num[j].Y do j := j - 1;
if i <= j then
begin
y := Num[i]; Num[i] := Num[j]; Num[j] := y;
i := i + 1; j := j - 1;
end;
until i > j;
if l < j then Sort(l, j);
if i < r then Sort(i, r);
end;

Begin
For I:=1 To N Do
Begin
If Num[I].X>Num[I].Y Then
Begin J:=Num[I].X; Num[I].X:=Num[I].Y; Num[I].Y:=J; End;
End;
Sort(1,N);
I:=0;
Last:=0;
Which:=0;
Repeat
Inc(I);
If Num[I].X>=Last Then
Begin Inc(Which); Last:=Num[I].Y; Left[Which]:=Num[I]; End;
Until I=N;
Writeln(Which);
For I:=1 To Which Do Writeln(Left[I].X,' ',Left[I].Y);
End.
Anybody can help me?
Posted by BYF 8 Nov 2002 08:25
> Program P1112;
>   Type
>     Coor=Record
>            X,Y:Integer;
>          End;
>   Var
>     N,I,J,Last,Which:Integer;
>     Num,Left:Array[1..100] Of Coor;
>
> procedure Sort(l, r: longint);
> var
>   i, j, x: longint;
>   Y:Coor;
> begin
>   i := l; j := r; x := Num[(l+r) DIV 2].Y;
>   repeat
>     while Num[i].Y < x do i := i + 1;
>     while x < Num[j].Y do j := j - 1;
>     if i <= j then
>     begin
>       y := Num[i]; Num[i] := Num[j]; Num[j] := y;
>       i := i + 1; j := j - 1;
>     end;
>   until i > j;
>   if l < j then Sort(l, j);
>   if i < r then Sort(i, r);
> end;
>
>   Begin
>     For I:=1 To N Do
>       Begin
>         If Num[I].X>Num[I].Y Then
>           Begin J:=Num[I].X; Num[I].X:=Num[I].Y; Num[I].Y:=J; End;
>       End;
>     Sort(1,N);
>     I:=0;
>     Last:=0;
>     Which:=0;
>     Repeat
>       Inc(I);
>       If Num[I].X>=Last Then
>         Begin Inc(Which); Last:=Num[I].Y; Left[Which]:=Num[I]; End;
>     Until I=N;
>     Writeln(Which);
>     For I:=1 To Which Do Writeln(Left[I].X,' ',Left[I].Y);
>   End.