ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Обсуждение задачи 1078. Отрезки

Why WA?Can anyone tell me some tests?(+)
Послано Acid Pea 28 май 2003 20:15
{I do it just like 1119}:
program p1078;
var a:array[1..500,1..2] of integer;
    f,place,v:array[0..500] of integer;
    n,i,j,t,max,j1,big:integer;
procedure init;
begin
     readln(n);
     for i:=1 to 500 do v[i]:=i;
     for i:=1 to n do
     begin
          read(a[i,1],a[i,2]);
          if a[i,1]>a[i,2] then
          begin
               t:=a[i,1];
               a[i,1]:=a[i,2];
               a[i,2]:=t;
          end;
     end;
end;
procedure sort;
begin
     for i:=1 to n-1 do
         for j:=1 to n-i do
         begin
              if (a[j,1]<a[j+1,1])and(a[j,2]>a[j+1,2]) then
              begin
                   t:=a[j,1];a[j,1]:=a[j+1,1];a[j+1,1]:=t;
                   t:=a[j,2];a[j,2]:=a[j+1,2];a[j+1,2]:=t;
                   t:=v[j];v[j]:=v[j+1];v[j+1]:=t;
              end;
         end;
end;
procedure solve(p:integer);
begin
     if p<>place[p] then solve(place[p]);
     write(v[p],' ');
end;
begin
     init;
     if n=0 then begin writeln(0);halt;end;
     sort;
     f[0]:=0;
     for i:=1 to n do
     begin
          max:=0;j1:=i;
          for j:=0 to i do
              if (a[j,1]>a[i,1])and(a[j,2]<a[i,2]) then
                 if f[j]+1>max then
                 begin
                      max:=f[j]+1;
                      j1:=j;
                 end;
          f[i]:=max;place[i]:=j1;
     end;
     big:=-maxint;
     for i:=1 to n do if big<f[i] then
     begin
          big:=f[i];
          j:=i;
     end;
     writeln(f[j]+1);
     solve(j);
     writeln;
     readln;
end.
Re: change you name
Послано ACer 28 май 2003 20:33
> {I do it just like 1119}:
> program p1078;
> var a:array[1..500,1..2] of integer;
>     f,place,v:array[0..500] of integer;
>     n,i,j,t,max,j1,big:integer;
> procedure init;
> begin
>      readln(n);
>      for i:=1 to 500 do v[i]:=i;
>      for i:=1 to n do
>      begin
>           read(a[i,1],a[i,2]);
>           if a[i,1]>a[i,2] then
>           begin
>                t:=a[i,1];
>                a[i,1]:=a[i,2];
>                a[i,2]:=t;
>           end;
>      end;
> end;
> procedure sort;
> begin
>      for i:=1 to n-1 do
>          for j:=1 to n-i do
>          begin
>               if (a[j,1]<a[j+1,1])and(a[j,2]>a[j+1,2]) then {I
think you can delete a[j,2]>a[j+1,2]}
>               begin
>                    t:=a[j,1];a[j,1]:=a[j+1,1];a[j+1,1]:=t;
>                    t:=a[j,2];a[j,2]:=a[j+1,2];a[j+1,2]:=t;
>                    t:=v[j];v[j]:=v[j+1];v[j+1]:=t;
>               end;
>          end;
> end;
> procedure solve(p:integer);
> begin
>      if p<>place[p] then solve(place[p]);
>      write(v[p],' ');
> end;
> begin
>      init;
>      if n=0 then begin writeln(0);halt;end;
>      sort;
>      f[0]:=0;
>      for i:=1 to n do
>      begin
>           max:=0;j1:=i;
>           for j:=0 to i do { j<-- 1 to i-1 and max=1}
>               if (a[j,1]>a[i,1])and(a[j,2]<a[i,2]) then
>                  if f[j]+1>max then
>                  begin
>                       max:=f[j]+1;
>                       j1:=j;
>                  end;
>           f[i]:=max;place[i]:=j1;
>      end;
>      big:=-maxint;
>      for i:=1 to n do if big<f[i] then
>      begin
>           big:=f[i];
>           j:=i;
>      end;
>      writeln(f[j]+1);
>      solve(j);
>      writeln;
>      readln;
> end.
I always do kind this mistake!Please look inside!
Послано Acid Pea 29 май 2003 19:40
> {I do it just like 1119}:
> program p1078;
> var a:array[1..500,1..2] of integer;
>     f,place,v:array[0..500] of integer;
>     n,i,j,t,max,j1,big:integer;
> procedure init;
> begin
>      readln(n);
>      for i:=1 to 500 do v[i]:=i;
>      for i:=1 to n do
>      begin
>           read(a[i,1],a[i,2]);
>           if a[i,1]>a[i,2] then
>           begin
>                t:=a[i,1];
>                a[i,1]:=a[i,2];
>                a[i,2]:=t;
>           end;
>      end;
> end;
> procedure sort;
> begin
>      for i:=1 to n-1 do
>          for j:=1 to n-i do
>          begin
>               if (a[j,1]<a[j+1,1])and{change to "or"}(a[j,2]>a
[j+1,2]) then
>               begin
>                    t:=a[j,1];a[j,1]:=a[j+1,1];a[j+1,1]:=t;
>                    t:=a[j,2];a[j,2]:=a[j+1,2];a[j+1,2]:=t;
>                    t:=v[j];v[j]:=v[j+1];v[j+1]:=t;
>               end;
>          end;
> end;
> procedure solve(p:integer);
> begin
>      if p<>place[p] then solve(place[p]);
>      write(v[p],' ');
> end;
> begin
>      init;
>      if n=0 then begin writeln(0);halt;end;
>      sort;
>      f[0]:=0;
>      for i:=1 to n do
>      begin
>           max:=0;j1:=i;
>           for j:=0{change to 1} to i do
>               if (a[j,1]>a[i,1])and(a[j,2]<a[i,2]) then
>                  if f[j]+1>max then
>                  begin
>                       max:=f[j]+1;
>                       j1:=j;
>                  end;
>           f[i]:=max;place[i]:=j1;
>      end;
>      big:=-maxint;
>      for i:=1 to n do if big<f[i] then
>      begin
>           big:=f[i];
>           j:=i;
>      end;
>      writeln(f[j]+1);
>      solve(j);
>      writeln;
>      readln;
> end.
{then you can got AC!}