main.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package main
  2. import (
  3. "fmt"
  4. )
  5. func main() {
  6. var T, N int
  7. fmt.Scan(&T)
  8. for cid := 0; cid < T; cid++ {
  9. fmt.Scan(&N)
  10. // ********** This is the standard answer given by GCJ **********
  11. // Assume that minimum energy is E, for each (xi, yi, zi),
  12. // we have |x-xi| + |y-yi| + |z-zi| <= Epi, which is
  13. // xi + yi + zi - Epi <= x + y + z <= Epi + xi + yi + zi
  14. // xi - yi + zi - Epi <= x - y + z <= Epi + xi - yi + zi
  15. // xi + yi - zi - Epi <= x + y - z <= Epi + xi + yi - zi
  16. // yi + zi - xi - Epi <= y + z - x <= Epi - xi + yi + zi
  17. // so 0 <= Epi. What's more,
  18. // A - x <= y + z <= B - x, G + x <= y + z <= H + x,
  19. // x - D <= y - z <= x - C, E - x <= y - z <= F - x
  20. // if y and z is solvable, then [A-x, B-x] and [G+x, H+x] must
  21. // intersect, [x-D, x-C] and [E-x, F-x] must intersect.
  22. // For first two range, x in [(A-H)/2, (B-G)/2], for the second,
  23. // x in [(E+C)/2, (F+D)/2]. So we just have to test if the two
  24. // range intersects.
  25. // ???
  26. // **************************************************************
  27. // In fact, the position of mother ship should be in the cuboid
  28. // area between two of the ships. For ship A and ship B, we
  29. // have: |x-xa|+|y-ya|+|z-za| = paE, |x-xb|+|y-yb|+|z-zb| = pbE;
  30. // so dista + distb = (pa + pb)E, E = distab / (pa + pb)
  31. // max E = max (distab/(pa+pb))
  32. ships := make([][]int, N)
  33. for i := 0; i < N; i++ {
  34. ships[i] = make([]int, 4)
  35. fmt.Scan(&ships[i][0], &ships[i][1], &ships[i][2], &ships[i][3])
  36. }
  37. maxPower := 0.
  38. for i := 0; i < N; i++ {
  39. for j := 0; j < N; j++ {
  40. dist := abs(ships[i][0]-ships[j][0]) + abs(ships[i][1]-ships[j][1]) + abs(ships[i][2]-ships[j][2])
  41. powerSum := ships[i][3] + ships[j][3]
  42. power := float64(dist) / float64(powerSum)
  43. if maxPower < power {
  44. maxPower = power
  45. }
  46. }
  47. }
  48. fmt.Printf("Case #%d: %f\n", cid+1, maxPower)
  49. }
  50. }