소스 검색

Revert "Check recursive algorithm gives a correct result on scoreboard"

This reverts commit b1a7f7bdbf44ba606a2572a7709f632fe0bb9211.
Guillaume Koenig 7 년 전
부모
커밋
d7f9d3c460
1개의 변경된 파일12개의 추가작업 그리고 30개의 파일을 삭제
  1. 12 30
      main.go

+ 12 - 30
main.go

@@ -137,23 +137,6 @@ func max(a, b int) int {
137
 
137
 
138
 var bestTotalScore int
138
 var bestTotalScore int
139
 
139
 
140
-func save() {
141
-	if bestTotalScore < 10900000 {
142
-		// TODO find a better way to avoid too many writes
143
-		return
144
-	}
145
-	output.Truncate(0)
146
-	output.Seek(0, 0)
147
-	for _, c := range Cars {
148
-		fmt.Fprintf(output, "%d", len(c.Rides))
149
-		for _, ri := range c.Rides {
150
-			fmt.Fprintf(output, " %d", ri)
151
-		}
152
-		fmt.Fprintf(output, "\n")
153
-	}
154
-	fmt.Printf("%d\n", bestTotalScore)
155
-}
156
-
157
 // invariant : when entering and leaving function,
140
 // invariant : when entering and leaving function,
158
 // Sched has the "same" heap. Same means successive
141
 // Sched has the "same" heap. Same means successive
159
 // popped values will be the same (but the internal
142
 // popped values will be the same (but the internal
@@ -161,7 +144,6 @@ func save() {
161
 func Choose(cumulativeScore int, depth int) {
144
 func Choose(cumulativeScore int, depth int) {
162
 	if cumulativeScore > bestTotalScore {
145
 	if cumulativeScore > bestTotalScore {
163
 		bestTotalScore = cumulativeScore
146
 		bestTotalScore = cumulativeScore
164
-		save()
165
 	}
147
 	}
166
 	c := Sched.Pop()
148
 	c := Sched.Pop()
167
 	if c == nil {
149
 	if c == nil {
@@ -180,7 +162,7 @@ func Choose(cumulativeScore int, depth int) {
180
 		if r.used {
162
 		if r.used {
181
 			continue
163
 			continue
182
 		}
164
 		}
183
-		if r.Length() > 8000 {
165
+		if r.Length() > 6000 {
184
 			continue
166
 			continue
185
 		}
167
 		}
186
 		if r.f < c.EarliestFinish(r) {
168
 		if r.f < c.EarliestFinish(r) {
@@ -199,8 +181,8 @@ func Choose(cumulativeScore int, depth int) {
199
 			// shitty sort-of-correct-but-quite-incorrect way
181
 			// shitty sort-of-correct-but-quite-incorrect way
200
 			// of picking next best n rides
182
 			// of picking next best n rides
201
 			n := 1
183
 			n := 1
202
-			if rand.Intn(max(1, int(N/20))) == 0 {
203
-				n = 2
184
+			if rand.Intn(max(1, int(N/5))) == 0 {
185
+				n = 3
204
 			}
186
 			}
205
 			if len(bestRides) > n {
187
 			if len(bestRides) > n {
206
 				bestRides = bestRides[len(bestRides)-n:]
188
 				bestRides = bestRides[len(bestRides)-n:]
@@ -211,15 +193,6 @@ func Choose(cumulativeScore int, depth int) {
211
 	// 	fmt.Printf("Picking %d %d -> %d %d\n", bestRide.a, bestRide.b, bestRide.x, bestRide.y)
193
 	// 	fmt.Printf("Picking %d %d -> %d %d\n", bestRide.a, bestRide.b, bestRide.x, bestRide.y)
212
 	// }
194
 	// }
213
 	if len(bestRides) != 0 {
195
 	if len(bestRides) != 0 {
214
-		if (len(bestRides)) >= 2 {
215
-			// if big difference in length, try both
216
-			// otherwise pick best according to score
217
-			d := abs(bestRides[0].r.length() - bestRides[1].r.length())
218
-			if d < 1000 {
219
-				bestRides = bestRides[1:]
220
-			}
221
-
222
-		}
223
 		for _, br := range bestRides {
196
 		for _, br := range bestRides {
224
 			r := br.r
197
 			r := br.r
225
 			r.used = true
198
 			r.used = true
@@ -263,6 +236,15 @@ func solve() {
263
 
236
 
264
 	// start recursion
237
 	// start recursion
265
 	Choose(0, 0)
238
 	Choose(0, 0)
239
+
240
+	for _, c := range Cars {
241
+		fmt.Fprintf(output, "%d", len(c.Rides))
242
+		for _, ri := range c.Rides {
243
+			fmt.Fprintf(output, " %d", ri)
244
+		}
245
+		fmt.Fprintf(output, "\n")
246
+	}
247
+	fmt.Printf("%d\n", bestTotalScore)
266
 }
248
 }
267
 
249
 
268
 func main() {
250
 func main() {