fork download
  1. program chasing;
  2. Uses Math;
  3.  
  4. var
  5. Bs, Bx, By, Ds, Dx, Dy, T, dist : LongInt;
  6. dir : Char;
  7. tdog,spostpall,nuovacoordpall : 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. if dir='R' then
  22. begin
  23. dist:=abs(Dx-Bx);
  24. tdog:=abs(Dy-By)/Ds;
  25. spostpall:=Bs*tdog;
  26. nuovacoordpall:=Bx+spostpall;
  27. if nuovacoordpall<=Dx then Ds:=-Ds
  28. else if Ds<=Bs then begin writeln(-1); exit; end;
  29. T:=ceil(tdog+(abs(dist-spostpall))/(abs(Ds-Bs)));
  30. end;
  31. if dir='L' then
  32. begin
  33. BS:=-Bs;
  34. dist:=abs(Dx-Bx);
  35. tdog:=abs(Dy-By)/Ds;
  36. spostpall:=Bs*tdog;
  37. nuovacoordpall:=Bx+spostpall;
  38. if nuovacoordpall<=Dx then begin if Ds<=abs(Bs) then begin writeln(-1); exit; end
  39. else Ds:=-Ds;
  40. end;
  41.  
  42. T:=ceil(tdog+(abs(dist-spostpall))/(abs(Ds-Bs)));
  43. end;
  44. if dir='D' then
  45. begin
  46. BS:=-Bs;
  47. dist:=abs(Dy-By);
  48. tdog:=(abs(Dx-Bx)/Ds);
  49. spostpall:=Bs*tdog;
  50. nuovacoordpall:=By+spostpall;
  51. if nuovacoordpall<Dy then begin if Ds<=abs(Bs) then begin writeln(-1); exit; end
  52. else Ds:=-Ds;
  53. end;
  54.  
  55. T:=ceil(tdog+ (abs(dist-spostpall))/(abs(Ds-Bs)));
  56. end;
  57. if dir='U' then
  58. begin
  59. dist:=abs(Dy-By);
  60. tdog:=abs(Dx-Bx)/Ds;
  61. spostpall:=Bs*tdog;
  62. nuovacoordpall:=By+spostpall;
  63. if nuovacoordpall<=Dy then Ds:=-Ds
  64. else if Ds<=Bs then begin writeln(-1); exit; end;
  65. T:= ceil(tdog+(abs(dist-spostpall))/(abs(Ds-Bs)));
  66. end;
  67.  
  68. writeln('ddd ',T);
  69. end.
Success #stdin #stdout 0s 5280KB
stdin
3 0 4
-2 0 3
L
stdout
ddd 5