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