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