fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. class Main
  6. {
  7. private static double distance(long X1, long Y1, long X2, long Y2)
  8. {
  9. return Math.sqrt((X1-X2)*(X1-X2) + (Y1-Y2)*(Y1-Y2));
  10. }
  11. public static void main (String[] args) throws java.lang.Exception
  12. {
  13. Scanner in = new Scanner(System.in);
  14. long A = in.nextLong();
  15. long B = in.nextLong();
  16. long C = in.nextLong();
  17. long X1 = in.nextLong();
  18. long Y1 = in.nextLong();
  19. long X2 = in.nextLong();
  20. long Y2 = in.nextLong();
  21. long Z2 = in.nextLong();
  22. double S = 10000000;
  23. if (Z2 == 0)
  24. {
  25. S = distance(X1, Y1, X2, Y2);
  26. }
  27. else
  28. {
  29. if (X2 == 0)
  30. {
  31. S = Math.min(distance(X1, Y1, -Z2, Y2), distance(X1, Y1, -Y2, -Z2));
  32. S = Math.min(S, distance(X1, Y1, Y2 - B, B + Z2));
  33. }
  34. if (X2 == A)
  35. {
  36. S = Math.min (distance(X1, Y1, Z2 + A, Y2), distance(X1, Y1, A + Y2, -Z2));
  37. S = Math.min(S, distance(X1, Y1, A + B - Y2, Z2 + B));
  38. }
  39. if (Y2 == 0)
  40. {
  41. S = Math.min(S, distance(X1, Y1, X2, -Z2));
  42. S = Math.min(S, distance(X1, Y1, -Z2, -X2));
  43. S = Math.min(S, distance(X1, Y1, A + Z2, X2 - A));
  44. }
  45. if (Y2 == B)
  46. {
  47. S = Math.min(S, distance(X1, Y1, X2, Z2 + B));
  48. S = Math.min(S, distance(X1, Y1, -Z2, X2 + B));
  49. S = Math.min(S, distance(X1, Y1, A + Z2, B + A - X2));
  50. }
  51. if ((Y2 != 0) && (Y2 != B) && (X2 != 0) && (X2 != A))
  52. {
  53. S = Math.min(C + distance(X1, Y1, X2, Y2), distance(X1, Y1, X2, -Y2 - C));
  54. S = Math.min(S, distance(X1, Y1, X2, 2*B - Y2 + C));
  55. S = Math.min(S, distance(X1, Y1, -X2 - C, Y2));
  56. S = Math.min(S, distance(X1, Y1, 2*A - X2 + C, Y2));
  57. S = Math.min(S, distance(X1, Y1, A + B + C - Y2, A + B - X2));
  58. S = Math.min(S, distance(X1, Y1, A + C + Y2, X2 - A));
  59. S = Math.min(S, distance(X1, Y1, -C - Y2, -X2));
  60. S = Math.min(S, distance(X1, Y1, Y2 - B - C, B + X2));
  61. S = Math.min(S, distance(X1, Y1, A + B - Y2, A + B + C - X2));
  62. S = Math.min(S, distance(X1, Y1, Y2 - B, B + C + X2));
  63. S = Math.min(S, distance(X1, Y1, -Y2, -C - X2));
  64. S = Math.min(S, distance(X1, Y1, A + Y2, -A - C + X2));
  65. }
  66. }
  67. System.out.printf("%.2f", S);
  68. }
  69. }
Success #stdin #stdout 0.07s 2184192KB
stdin
4 7 3
2 1
3 7 2
stdout
8.06