fork download
  1. program chasing;
  2. Uses Math;
  3.  
  4. var
  5. Bs, Bx, By, Ds, Dx, Dy : LongInt;
  6. dir : Char;
  7. T : real;
  8. begin
  9. (*
  10.   assign(input, 'input.txt'); reset(input);
  11.   assign(output, 'output.txt'); rewrite(output);
  12. *)
  13.  
  14. ReadLn(Dx, Dy, Ds);
  15.  
  16. ReadLn(Bx, By, Bs);
  17.  
  18. ReadLn(dir);
  19.  
  20. T := 0;
  21.  
  22.  
  23. if (Dx<Bx) and (Ds<Bs) and (dir='R') then T:=-1
  24. else if (Dx>Bx) and (Ds<Bs) and (dir='L') then T:=-1
  25. else if (Ds<Bs) and (dir='D') then T:=-1
  26. else if (Dy<By) and (Ds<Bs) and (dir='U') then T:=-1
  27. else
  28. begin
  29. if (dir='D') or (dir='L') then Bs:=-Bs;
  30. if (dir='R') or (dir='L') then T:= (abs(Dy-By))/Ds + (abs(Dx-Bx)) / (abs (Ds-Bs))
  31. else if (dir='U') or (dir='D') then T:= (abs(Dx-Bx))/Ds + (abs(Dy-By)) / (abs (Ds-Bs)) ;
  32. end;
  33.  
  34. WriteLn(ceil(T));
  35.  
  36. end.
Success #stdin #stdout 0.01s 5288KB
stdin
1 2 1
6 4 3
D
stdout
-1