ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1078. Segments

Please, help! What's Wrong with my solution!
Posted by 1 1 Jun 2003 22:08
const
 nmax=500;
type
 s=array[-1..nmax] of integer;
 s1=array[1..2] of integer;
var
 n:integer;
 a:array[1..nmax] of s;
 i,j,k,min,max:integer;
 M:array[1..nmax] of s1;
 b:array[1..nmax] of integer;
 procedure init;
  begin
   fillchar(a,sizeof(a),0);
   fillchar(b,sizeof(b),0);
   readln(n);
   for i:=1 to n do
    begin
    readln(m[i,1],m[i,2]);
     if m[i,1]>m[i,2] then  begin
            j:=m[i,1];
           m[i,1]:=m[i,2];
           m[i,2]:=j;  end;

    end;
  end;

 function online(x,y:integer):boolean;   {x in y}
  begin
  if ((m[y,1]<m[x,1]) and (m[x,2]<m[y,2])) and (m[x,1]<>m[x,2]) then
online:=true
                                 else online:=false;
  end;

 procedure check(k:integer);
  var i:integer;
  begin
   for i:=1 to n do
    if online(k,i) then
               begin
                a[i,k]:=1;
                a[k,i]:=1;
             if   a[k,-1]<=a[i,-1] then
                a[k,-1]:=a[i,-1]+1;
               end;

  end;

 function find:integer;
  var max:integer;
      i:integer;
  begin
   max:=1;
  for i:=2 to n do
   if a[max,-1]<a[i,-1] then max:=i;
    find:=max;
  end;

 procedure print(k:integer);
  var
   s:integer;
  begin
  s:=1;
  if a[k,-1]=0 then begin
                     writeln(k);
                     halt;
                    end;
   for i:=1 to n do
    if a[i,k]=1 then
     begin
      if a[i,-1]=a[k,-1]-1 then begin write(k,' '); print
(i);exit;end;

     end;

  end;

begin
 init;
 for i:=1 to n do check(i);
 writeln(a[find,-1]+1);
 i:=find;
 print(i);
end.
Re: Please, help! What's Wrong with my solution!
Posted by Ural_??? 3 Jun 2003 20:22
you could use qsort at first and compare two line