fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <math.h>
  4. #include <queue>
  5. #include <set>
  6. #include <string>
  7. #define INF 0x3f3f3f3f
  8. #define pb push_back
  9. #define mp make_pair
  10.  
  11. using namespace std;
  12.  
  13. double Lx,Ly,Gx,Gy,ans_min,ans_max,Cx,Cy;
  14.  
  15. double dist(double x1, double y1, double x2, double y2)
  16. {
  17. double x, y;
  18. x = x1-x2; y = y1-y2;
  19. return sqrt(x*x+y*y);
  20. }
  21.  
  22. /*
  23. 7
  24. FFRRRFBBB
  25. 0 0 -12 -3
  26. */
  27.  
  28. void Move(char c)
  29. {
  30. if(c == 'L') Cx--;
  31. if(c == 'R') Cx++;
  32. if(c == 'F') Cy++;
  33. if(c == 'B') Cy--;
  34. else return;
  35. }
  36. /*
  37. 3
  38. BBRRFFRBBBBB
  39. 0 0
  40. -5 3
  41. */
  42. int main()
  43. {
  44. string s;
  45. int k;
  46. cin >> k >> s;
  47. cin >> Lx >> Ly >> Gx >> Gy;
  48. Cx = Gx; Cy = Gy;
  49. double in_dist = dist(Gx,Gy,Lx,Ly),cur_dist;
  50. ans_min = ans_max = in_dist;
  51. cur_dist = in_dist;
  52. for(int i = 0; i < s.length(); i++)
  53. {
  54. if(s[i] == 'I') continue;
  55. Move(s[i]);
  56. cur_dist = dist(Cx, Cy, Lx, Ly);
  57. ans_max = max(ans_max, cur_dist);
  58. ans_min = min(ans_min, cur_dist);
  59. }
  60. double dx = Cx - Gx, dy = Cy - Gy;
  61. int q = 0;
  62. if(cur_dist == in_dist){cout.precision(9);cout<<fixed<<ans_min<<" "<<ans_max<<endl; return 0;}
  63. if(cur_dist < in_dist) q = 1;
  64. double last_dist = cur_dist;
  65. for(int j = 0; j < k-5; j++)
  66. {
  67. cur_dist = dist(Cx, Cy, Lx, Ly);
  68. ans_max = max(cur_dist, ans_max);
  69. ans_min = min(cur_dist, ans_min);
  70. Cx += dx;
  71. Cy += dy;
  72. cur_dist = dist(Cx, Cy, Lx, Ly);
  73. if(q && (cur_dist >= last_dist))
  74. {
  75. Cx -= dx*2;
  76. Cy -= dy*2;
  77. cur_dist = dist(Cx, Cy, Lx, Ly);
  78. for(int i = 0; i < 2*s.length(); i++)
  79. {
  80. if(s[i%s.length()] == 'I') continue;
  81. Move(s[i%s.length()]);
  82. cur_dist = dist(Cx, Cy, Lx, Ly);
  83. ans_max = max(cur_dist, ans_max);
  84. ans_min = min(cur_dist, ans_min);
  85. }
  86. q = 0;
  87. }
  88. last_dist = cur_dist;
  89. }
  90. for(int i = 0; i < s.length()*4; i++)
  91. {
  92. if(s[i] == 'I') continue;
  93. Move(s[i%s.length()]);
  94. cur_dist = dist(Cx, Cy, Lx, Ly);
  95. ans_max = max(ans_max, cur_dist);
  96. ans_min = min(ans_min, cur_dist);
  97. }
  98. cout.precision(9);
  99. cout << fixed << ans_min << " " << ans_max << endl;
  100. return 0;
  101. }
  102.  
Success #stdin #stdout 0s 2736KB
stdin
Standard input is empty
stdout
0.000000000 0.000000000