ソースを参照

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 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 140
 // invariant : when entering and leaving function,
158 141
 // Sched has the "same" heap. Same means successive
159 142
 // popped values will be the same (but the internal
@@ -161,7 +144,6 @@ func save() {
161 144
 func Choose(cumulativeScore int, depth int) {
162 145
 	if cumulativeScore > bestTotalScore {
163 146
 		bestTotalScore = cumulativeScore
164
-		save()
165 147
 	}
166 148
 	c := Sched.Pop()
167 149
 	if c == nil {
@@ -180,7 +162,7 @@ func Choose(cumulativeScore int, depth int) {
180 162
 		if r.used {
181 163
 			continue
182 164
 		}
183
-		if r.Length() > 8000 {
165
+		if r.Length() > 6000 {
184 166
 			continue
185 167
 		}
186 168
 		if r.f < c.EarliestFinish(r) {
@@ -199,8 +181,8 @@ func Choose(cumulativeScore int, depth int) {
199 181
 			// shitty sort-of-correct-but-quite-incorrect way
200 182
 			// of picking next best n rides
201 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 187
 			if len(bestRides) > n {
206 188
 				bestRides = bestRides[len(bestRides)-n:]
@@ -211,15 +193,6 @@ func Choose(cumulativeScore int, depth int) {
211 193
 	// 	fmt.Printf("Picking %d %d -> %d %d\n", bestRide.a, bestRide.b, bestRide.x, bestRide.y)
212 194
 	// }
213 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 196
 		for _, br := range bestRides {
224 197
 			r := br.r
225 198
 			r.used = true
@@ -263,6 +236,15 @@ func solve() {
263 236
 
264 237
 	// start recursion
265 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 250
 func main() {