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 1162. Currency Exchange

What's wrong with my program (Pascal)? Need help or some AC tests!
Posted by Alien 7 May 2002 06:39
program P1162;
{$APPTYPE CONSOLE}
uses
  SysUtils;

const Max=100;
var
  n,m,s:integer;
  Value,Temp:real;
  a:array[1..Max] of real;
  b:array[1..Max] of 0..1;
  c:array[1..Max] of 0..100;
  AB:array[1..2*Max,1..2] of integer;
  RV:array[1..2*Max,1..2] of real;
  i,j,ci,cx,x,y:integer;
procedure input;
var
  i:integer;
begin
  readln(n,m,s,Value);
  for i:=1 to n do
  begin
    a[i]:=0;
    b[i]:=0;
    c[i]:=0;
  end;
  a[1]:=Value; b[1]:=1;
  cx:=1; c[1]:=1;
  for i:=1 to m do
  begin
    read(x,y);
    AB[i,1]:=x; AB[i,2]:=y;
    read(RV[i,1],RV[i,2]);
    AB[m+i,1]:=y; AB[m+i,2]:=x;
    read(RV[m+i,1],RV[m+i,2]);
  end;
end;
procedure main;
function FindValue(x:integer):real;
var
  Te:real;
begin
  Te:=(a[AB[x,1]]-RV[x,2])*RV[x,1];
  FindValue:=Te;
end;
begin
  ci:=1;
  while ci<=cx do
  begin
    for i:=1 to 2*m do
    if AB[i,1]=c[ci] then
    begin
      j:=AB[i,2];
      Temp:=FindValue(i);
      if Temp>a[j] then
      begin
        a[j]:=Temp;
        if b[j]=0 then
        begin
          b[j]:=1;
          inc(cx);
          c[cx]:=j;
        end;
      end;
      if a[1]>Value then
      begin
        writeln('YES');
        halt(0);
      end;
    end;
    b[c[1]]:=0;
    dec(cx);
    for i:=1 to cx do
      c[i]:=c[i+1];
  end;
  writeln('NO');
end;
begin
  input;
  main;
end.
Ural uses Free Pascal to test your program. So {$apptype console} and uses sysutils is illegal!
Posted by Koala 26 Feb 2003 16:58
> program P1162;
> {$APPTYPE CONSOLE}
> uses
>   SysUtils;
>
> const Max=100;
> var
>   n,m,s:integer;
>   Value,Temp:real;
>   a:array[1..Max] of real;
>   b:array[1..Max] of 0..1;
>   c:array[1..Max] of 0..100;
>   AB:array[1..2*Max,1..2] of integer;
>   RV:array[1..2*Max,1..2] of real;
>   i,j,ci,cx,x,y:integer;
> procedure input;
> var
>   i:integer;
> begin
>   readln(n,m,s,Value);
>   for i:=1 to n do
>   begin
>     a[i]:=0;
>     b[i]:=0;
>     c[i]:=0;
>   end;
>   a[1]:=Value; b[1]:=1;
>   cx:=1; c[1]:=1;
>   for i:=1 to m do
>   begin
>     read(x,y);
>     AB[i,1]:=x; AB[i,2]:=y;
>     read(RV[i,1],RV[i,2]);
>     AB[m+i,1]:=y; AB[m+i,2]:=x;
>     read(RV[m+i,1],RV[m+i,2]);
>   end;
> end;
> procedure main;
> function FindValue(x:integer):real;
> var
>   Te:real;
> begin
>   Te:=(a[AB[x,1]]-RV[x,2])*RV[x,1];
>   FindValue:=Te;
> end;
> begin
>   ci:=1;
>   while ci<=cx do
>   begin
>     for i:=1 to 2*m do
>     if AB[i,1]=c[ci] then
>     begin
>       j:=AB[i,2];
>       Temp:=FindValue(i);
>       if Temp>a[j] then
>       begin
>         a[j]:=Temp;
>         if b[j]=0 then
>         begin
>           b[j]:=1;
>           inc(cx);
>           c[cx]:=j;
>         end;
>       end;
>       if a[1]>Value then
>       begin
>         writeln('YES');
>         halt(0);
>       end;
>     end;
>     b[c[1]]:=0;
>     dec(cx);
>     for i:=1 to cx do
>       c[i]:=c[i+1];
>   end;
>   writeln('NO');
> end;
> begin
>   input;
>   main;
> end.