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? Please,help me!!!
Posted by Nazarov Denis (nsc2001@rambler.ru) 13 Jan 2002 15:30
My program:

Program t1162;{$N+}

Const MaxM=100;
      Eps=1E-15;

Type Point=record
      S1,S2  :integer;
      RS1S2  :extended;
      CS1S2  :extended;
      RS2S1  :extended;
      CS2S1  :extended;
     end;

Var  N,M,S,i,j    :integer;
     V,CurV       :extended;
     CurS,step    :integer;
     P            :array[1..MaxM]of Point;

Procedure Rec;
var i     :integer;
    predv :extended;
 begin
  step:=step+1;
  if CurS=S then
   if CurV-V>Eps then begin
    Writeln('YES');
    Halt(0);
   end;
  if step>15000 then exit;
  predv:=curv;
  for i:=1 to m do
   if p[i].s1=curs then
    if curv>p[i].cs1s2 then begin
     curs:=p[i].s2;
     curv:=(curv-p[i].cs1s2)*p[i].rs1s2;
     rec;
     curv:=predv;
     curs:=p[i].s1;
    end;
  for i:=1 to m do
   if p[i].s2=curs then
    if curv>p[i].cs2s1 then begin
     curs:=p[i].s1;
     curv:=(curv-p[i].cs2s1)*p[i].rs2s1;
     rec;
     curv:=predv;
     curs:=p[i].s2;
    end;
  step:=step-1;
 end;

begin
 Read(N,M,S,V);
 for i:=1 to M do
  read(P[i].S1,P[i].S2,P[i].rS1S2,P[i].cS1S2,P[i].rS2S1,P[i].cS2S1);
 CurV:=V;
 CurS:=S;
 step:=0;
 Rec;
 Writeln('NO');
end.
Re: What's wrong with my program? Please,help me!!!
Posted by Christopher Moh 13 Jan 2002 16:14
Well,

firstly, it may take more than 15000 steps before a correct solution
is found.  15000 is way too little actually...

secondly, isn't your solution kind of slow?  There's a polynomial
time algorithm to solve it.
There is a solution of O(m*n), right?
Posted by shitty.Mishka 13 Jan 2002 18:14
Yes, there is an algorithm of O(MN)
Posted by Christopher Moh 13 Jan 2002 21:23
Re: I don't know this algorithm, but my solution is very fast. You can see it in statistic.
Posted by Nazarov Denis (nsc2001@rambler.ru) 13 Jan 2002 22:12
>