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

O,God! I'll go mad! Who can help me and give me some tests,I'll be grateful.(+)
Posted by sunoi 25 Oct 2004 09:54
type arr=array[1..500,1..5] of integer;
     ar=array[1..500] of boolean;
var a:arr;
    d:ar;
    i,j,maxcode,max,n:integer;
function init(i,j:integer):boolean;
begin
  if (a[i,1]>a[j,1]) and (a[i,2]<a[j,2]) then init:=true
                                         else init:=false;
end;
procedure search(x:integer);
var i,j,m,mcode:integer;
begin
  m:=0;mcode:=0;
  for i:=1 to n do
  begin
    if init(i,x) then
        begin
          if d[i] then search(i);
          if a[i,3]>m then begin m:=a[i,3];mcode:=i;end;
        end;
  end;
  a[x,3]:=m+1;
  a[x,4]:=mcode;
  d[x]:=false;
end;
procedure printa(i:integer);
begin
  if a[i,4]<>0 then printa(a[i,4]);
  if i=maxcode then writeln(i)
               else write(i,' ');
end;
begin
  fillchar(d,sizeof(d),true);
  fillchar(a,sizeof(a),0);
  readln(n);
  if n=0 then begin writeln(0);halt;end;
  for i:=1 to n do
  begin
    readln(a[i,1],a[i,2]);
    if a[i,1]>a[i,2] then begin j:=a[i,1];a[i,1]:=a[i,2];a[i,2]:=j;end;
    a[i,3]:=1;
  end;
  max:=0;maxcode:=0;
  for i:=1 to n do
  begin
    if d[i] then search(i);
    if a[i,3]>maxcode then begin max:=a[i,3];maxcode:=i;end;
  end;
  i:=maxcode;
  writeln(max);
  printa(maxcode);
end.


A test case for you (+)
Posted by Michael Rybak (accepted@ukr.net) 26 Oct 2004 20:46
3
1 6
2 5
3 4
Re: A test case for you (+)
Posted by sunoi 30 Oct 2004 19:04
Thank you very much.With your help,i'v got AC now!:)