fork download
  1. program chasing;
  2. Uses Math;
  3.  
  4. var
  5. Bs, Bx, By, Ds, Dx, Dy, T, spostpall, dist, tdog, nuovacoordpall : LongInt;
  6. dir : Char;
  7.  
  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:=ceil(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+ ceil((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:=ceil(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+ ceil((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:=ceil(abs(Dx-Bx)/Ds);
  49. spostpall:=Bs*tdog; writeln(spostpall);
  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+ ceil((abs(dist-spostpall))/(abs(Ds-Bs))));
  56. end;
  57. if dir='U' then
  58. begin
  59. dist:=abs(Dy-By);
  60. tdog:=ceil(abs(Dx-Bx)/Ds);
  61. spostpall:=Bs*tdog;
  62. nuovacoordpall:=By+spostpall;
  63. if nuovacoordpall>Dy then begin if Ds<Bs then begin writeln(-1); exit; end
  64. else Ds:=-Ds;
  65. end;
  66.  
  67. T:=ceil( tdog+ ceil((abs(dist-spostpall))/(abs(Ds-Bs))));
  68. end;
  69.  
  70. writeln(T);
  71. end.
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
Success #stdin #stdout 0s 5316KB
stdin
7 -7 4
5 -8 3
D
stdout
-3
5