Browse Source

AC 2008 2 C

dengxinyi 6 years ago
parent
commit
e695837d61
5 changed files with 63 additions and 3 deletions
  1. 10 0
      2008/2/C/C-large-answers.out
  2. 10 0
      2008/2/C/C-small-answers.out
  3. 33 3
      2008/2/C/main.go
  4. 3 0
      2008/2/C/test.out
  5. 7 0
      2008/2/C/utils.go

+ 10 - 0
2008/2/C/C-large-answers.out

@@ -0,0 +1,10 @@
+Case #1: 52927.000000
+Case #2: 1049784.500000
+Case #3: 312235.500000
+Case #4: 110.000000
+Case #5: 2.333333
+Case #6: 55.000000
+Case #7: 244544.500000
+Case #8: 3.500000
+Case #9: 927897.500000
+Case #10: 24.309897

+ 10 - 0
2008/2/C/C-small-answers.out

@@ -0,0 +1,10 @@
+Case #1: 2.333333
+Case #2: 352018.000000
+Case #3: 6688.166667
+Case #4: 14159.500000
+Case #5: 3.500000
+Case #6: 5333.400000
+Case #7: 13.333333
+Case #8: 35.250000
+Case #9: 14.221677
+Case #10: 15.000000

+ 33 - 3
2008/2/C/main.go

@@ -9,14 +9,44 @@ func main() {
 	fmt.Scan(&T)
 	for cid := 0; cid < T; cid++ {
 		fmt.Scan(&N)
+		// ********** This is the standard answer given by GCJ **********
 		// Assume that minimum energy is E, for each (xi, yi, zi),
 		// we have |x-xi| + |y-yi| + |z-zi| <= Epi, which is
 		// xi + yi + zi - Epi <= x + y + z <= Epi + xi + yi + zi
 		// xi - yi + zi - Epi <= x - y + z <= Epi + xi - yi + zi
 		// xi + yi - zi - Epi <= x + y - z <= Epi + xi + yi - zi
-		// xi - yi - zi - Epi <= x - y - z <= Epi + xi - yi - zi
-		for n := 0; n < N; n++ {
-
+		// yi + zi - xi - Epi <= y + z - x <= Epi - xi + yi + zi
+		// so 0 <= Epi. What's more,
+		// A - x <= y + z <= B - x, G + x <= y + z <= H + x,
+		// x - D <= y - z <= x - C, E - x <= y - z <= F - x
+		// if y and z is solvable, then [A-x, B-x] and [G+x, H+x] must
+		// intersect, [x-D, x-C] and [E-x, F-x] must intersect.
+		// For first two range, x in [(A-H)/2, (B-G)/2], for the second,
+		// x in [(E+C)/2, (F+D)/2]. So we just have to test if the two
+		// range intersects.
+		// ???
+		// **************************************************************
+		// In fact, the position of mother ship should be in the cuboid
+		// area between two of the ships. For ship A and ship B, we
+		// have: |x-xa|+|y-ya|+|z-za| = paE, |x-xb|+|y-yb|+|z-zb| = pbE;
+		// so dista + distb = (pa + pb)E, E = distab / (pa + pb)
+		// max E = max (distab/(pa+pb))
+		ships := make([][]int, N)
+		for i := 0; i < N; i++ {
+			ships[i] = make([]int, 4)
+			fmt.Scan(&ships[i][0], &ships[i][1], &ships[i][2], &ships[i][3])
+		}
+		maxPower := 0.
+		for i := 0; i < N; i++ {
+			for j := 0; j < N; j++ {
+				dist := abs(ships[i][0]-ships[j][0]) + abs(ships[i][1]-ships[j][1]) + abs(ships[i][2]-ships[j][2])
+				powerSum := ships[i][3] + ships[j][3]
+				power := float64(dist) / float64(powerSum)
+				if maxPower < power {
+					maxPower = power
+				}
+			}
 		}
+		fmt.Printf("Case #%d: %f\n", cid+1, maxPower)
 	}
 }

+ 3 - 0
2008/2/C/test.out

@@ -0,0 +1,3 @@
+Case #1: 3.500000
+Case #2: 0.000000
+Case #3: 2.333333

+ 7 - 0
2008/2/C/utils.go

@@ -12,6 +12,13 @@ type Pair64 struct {
 	_2 int64
 }
 
+func abs(x int) int {
+	if x < 0 {
+		return -x
+	}
+	return x
+}
+
 func maxInt(nums ...int) int {
 	max := nums[0]
 	for i := 1; i < len(nums); i++ {