浏览代码

Some inputs perform better picking one of the next best rides

instead of picking the next best ride according to our score
function

With the few performing better, total score is now past 48M.
Guillaume Koenig 7 年之前
父节点
当前提交
1e502229e8
共有 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 {