ソースを参照

At 48M picking one of the next best rides (instead of the best)

Guillaume Koenig 7 年 前
コミット
e6528c2394
共有1 個のファイルを変更した27 個の追加11 個の削除を含む
  1. 27 11
      main.go

+ 27 - 11
main.go

@@ -133,17 +133,19 @@ func max(a, b int) int {
133
 }
133
 }
134
 
134
 
135
 func Choose(c *Car) *Ride {
135
 func Choose(c *Car) *Ride {
136
-	var bestRide *Ride
137
-	bestLenOfRide := 0
138
-	bestTotal := 0
136
+	var bestRides []struct {
137
+		r         *Ride
138
+		lenOfRide int
139
+		total     int
140
+	}
139
 	// fmt.Printf("car %d\n", c.ID)
141
 	// fmt.Printf("car %d\n", c.ID)
140
 	for _, r := range Rides {
142
 	for _, r := range Rides {
141
 		if r.used {
143
 		if r.used {
142
 			continue
144
 			continue
143
 		}
145
 		}
144
-		if r.Length() > 6000 {
145
-			continue
146
-		}
146
+		// if r.Length() > 6000 {
147
+		// 	continue
148
+		// }
147
 		if r.f < c.EarliestFinish(r) {
149
 		if r.f < c.EarliestFinish(r) {
148
 			continue
150
 			continue
149
 		}
151
 		}
@@ -151,16 +153,30 @@ func Choose(c *Car) *Ride {
151
 		lenOfRide := r.length()
153
 		lenOfRide := r.length()
152
 		total := max(c.distanceTo(r.a, r.b), r.s-c.Arrival) + lenOfRide
154
 		total := max(c.distanceTo(r.a, r.b), r.s-c.Arrival) + lenOfRide
153
 		// fmt.Printf("%d/%d\n", lenOfRide, total)
155
 		// fmt.Printf("%d/%d\n", lenOfRide, total)
154
-		if bestRide == nil || lenOfRide*bestTotal > total*bestLenOfRide {
155
-			bestLenOfRide = lenOfRide
156
-			bestTotal = total
157
-			bestRide = r
156
+		if len(bestRides) == 0 || lenOfRide*bestRides[len(bestRides)-1].total > total*bestRides[len(bestRides)-1].lenOfRide {
157
+			bestRides = append(bestRides, struct {
158
+				r         *Ride
159
+				lenOfRide int
160
+				total     int
161
+			}{r, lenOfRide, total})
162
+			// shitty sort-of-correct-but-quite-incorrect way
163
+			// of picking next best n rides
164
+			n := 3
165
+			if len(bestRides) > n {
166
+				bestRides = bestRides[len(bestRides)-n:]
167
+			}
158
 		}
168
 		}
159
 	}
169
 	}
160
 	// if bestRide != nil {
170
 	// if bestRide != nil {
161
 	// 	fmt.Printf("Picking %d %d -> %d %d\n", bestRide.a, bestRide.b, bestRide.x, bestRide.y)
171
 	// 	fmt.Printf("Picking %d %d -> %d %d\n", bestRide.a, bestRide.b, bestRide.x, bestRide.y)
162
 	// }
172
 	// }
163
-	return bestRide
173
+	if len(bestRides) != 0 {
174
+		// pick the not quite best ride...hey some
175
+		// of the inputs already  give a better score !
176
+		return bestRides[0].r
177
+		//return bestRides[len(bestRides)-1].r
178
+	}
179
+	return nil
164
 }
180
 }
165
 
181
 
166
 func assign() bool {
182
 func assign() bool {