浏览代码

AC 2008 3 A

dengxinyi 6 年之前
父节点
当前提交
b9c8d7f7c7
共有 5 个文件被更改,包括 281 次插入1 次删除
  1. 81 0
      2008/3/A/A-large-answers.out
  2. 70 0
      2008/3/A/A-small-answers.out
  3. 101 1
      2008/3/A/main.go
  4. 2 0
      2008/3/A/test.out
  5. 27 0
      2008/3/A/utils.go

+ 81 - 0
2008/3/A/A-large-answers.out

@@ -0,0 +1,81 @@
+Case #1: 6499
+Case #2: 20225
+Case #3: 276
+Case #4: 5305
+Case #5: 880547
+Case #6: 508
+Case #7: 11171
+Case #8: 132
+Case #9: 275
+Case #10: 846683
+Case #11: 3751
+Case #12: 24800
+Case #13: 266
+Case #14: 5301
+Case #15: 5382
+Case #16: 10851
+Case #17: 6651
+Case #18: 6637
+Case #19: 1626
+Case #20: 492
+Case #21: 6160
+Case #22: 21141
+Case #23: 263452
+Case #24: 1629
+Case #25: 510000
+Case #26: 38750
+Case #27: 1533
+Case #28: 3970
+Case #29: 208
+Case #30: 423
+Case #31: 606
+Case #32: 40131
+Case #33: 0
+Case #34: 213
+Case #35: 1745
+Case #36: 284
+Case #37: 208
+Case #38: 330
+Case #39: 13896
+Case #40: 11123
+Case #41: 340
+Case #42: 0
+Case #43: 6277
+Case #44: 1620
+Case #45: 1743
+Case #46: 0
+Case #47: 9261
+Case #48: 323
+Case #49: 880547
+Case #50: 246
+Case #51: 8905
+Case #52: 322
+Case #53: 6505
+Case #54: 996
+Case #55: 5559
+Case #56: 2308
+Case #57: 0
+Case #58: 39641
+Case #59: 2630
+Case #60: 8916
+Case #61: 6262
+Case #62: 5635
+Case #63: 11600
+Case #64: 474
+Case #65: 381
+Case #66: 598
+Case #67: 6625
+Case #68: 3901
+Case #69: 4
+Case #70: 1708
+Case #71: 1528
+Case #72: 3490
+Case #73: 6754
+Case #74: 21141
+Case #75: 11600
+Case #76: 8984
+Case #77: 0
+Case #78: 1752
+Case #79: 167
+Case #80: 1521
+Case #81: 7607

+ 70 - 0
2008/3/A/A-small-answers.out

@@ -0,0 +1,70 @@
+Case #1: 1328
+Case #2: 28
+Case #3: 29
+Case #4: 74
+Case #5: 58
+Case #6: 71
+Case #7: 76
+Case #8: 86
+Case #9: 139
+Case #10: 111
+Case #11: 941
+Case #12: 46
+Case #13: 0
+Case #14: 102
+Case #15: 67
+Case #16: 1328
+Case #17: 51
+Case #18: 194
+Case #19: 863
+Case #20: 67
+Case #21: 29
+Case #22: 920
+Case #23: 74
+Case #24: 84
+Case #25: 905
+Case #26: 36
+Case #27: 53
+Case #28: 58
+Case #29: 55
+Case #30: 71
+Case #31: 0
+Case #32: 747
+Case #33: 863
+Case #34: 850
+Case #35: 29
+Case #36: 133
+Case #37: 86
+Case #38: 54
+Case #39: 89
+Case #40: 79
+Case #41: 0
+Case #42: 929
+Case #43: 4
+Case #44: 916
+Case #45: 143
+Case #46: 117
+Case #47: 29
+Case #48: 890
+Case #49: 91
+Case #50: 59
+Case #51: 0
+Case #52: 226
+Case #53: 912
+Case #54: 144
+Case #55: 0
+Case #56: 136
+Case #57: 114
+Case #58: 169
+Case #59: 64
+Case #60: 73
+Case #61: 70
+Case #62: 930
+Case #63: 958
+Case #64: 45
+Case #65: 85
+Case #66: 70
+Case #67: 86
+Case #68: 62
+Case #69: 63
+Case #70: 79

+ 101 - 1
2008/3/A/main.go

@@ -9,6 +9,106 @@ func main() {
 	fmt.Scan(&N)
 	for cid := 0; cid < N; cid++ {
 		fmt.Scan(&L)
-		fmt.Printf("Case #%d: \n", cid+1)
+		const sideLen = 6000
+		vert, hori := make([][]bool, sideLen), make([][]bool, sideLen+1)
+		for i := range vert {
+			vert[i] = make([]bool, sideLen+1)
+		}
+		for i := range hori {
+			hori[i] = make([]bool, sideLen)
+		}
+		x, y := 3000, 3000
+		detX, detY := 0, 1
+		xMin, xMax, yMin, yMax := Pair{3000, 3000}, Pair{3000, 3000}, Pair{3000, 3000}, Pair{3000, 3000}
+		// For detail explanation, please refer to https://code.google.com/codejam/contest/32002/dashboard#s=a&a=0
+		for i := 0; i < L; i++ {
+			var move string
+			var repeat int
+			fmt.Scan(&move, &repeat)
+			for r := 0; r < repeat; r++ {
+				for _, m := range move {
+					switch m {
+					case 'L':
+						detX, detY = -detY, detX
+					case 'R':
+						detX, detY = detY, -detX
+					case 'F':
+						if detY == 0 { // Move towards x dir
+							hori[y][(2*x+detX)/2] = true
+						} else { // ... y dir
+							vert[(2*y+detY)/2][x] = true
+						}
+						x, y = x+detX, y+detY
+						if x < xMin._1 || (xMin._1 == x && y < xMin._2) {
+							xMin._1, xMin._2 = x, y
+						}
+						if xMax._1 < x || (xMax._1 == x && xMax._2 < y) {
+							xMax._1, xMax._2 = x, y
+						}
+						if y < yMin._2 || (yMin._2 == y && yMin._1 < x) {
+							yMin._1, yMin._2 = x, y
+						}
+						if yMax._2 < y || (yMax._2 == y && x < yMax._1) {
+							yMax._1, yMax._2 = x, y
+						}
+					}
+				}
+			}
+		} // Construct the edge graph and the position of 4 key points
+		//          v____           <-- yMax
+		//        __|    |___v      <-- xMax
+		//     __|           |
+		//    |              |
+		//    |____        __|
+		//    ^    |     _|         <-- xMin
+		//         |____|
+		//              ^           <-- yMin
+		polyArea := 0
+		for y := yMin._2; y < yMax._2; y++ {
+			cnt := 0
+			for x := xMin._1; x <= xMax._1; x++ {
+				if vert[y][x] {
+					cnt++
+				}
+				if cnt%2 == 1 { // Cross vert edge odd times: innner, even: outter
+					polyArea++
+				}
+			}
+		}
+		stairArea := 0
+		for x, hei := xMax._1-1, xMax._2; yMax._1 <= x; x-- {
+			for y := hei + 1; y <= yMax._2; y++ {
+				if hori[y][x] {
+					hei = y
+				}
+			}
+			stairArea += yMax._2 - hei
+		}
+		for y, hei := yMax._2-1, yMax._1; xMin._2 <= y; y-- {
+			for x := hei - 1; xMin._1 <= x; x-- {
+				if vert[y][x] {
+					hei = x
+				}
+			}
+			stairArea += hei - xMin._1
+		}
+		for x, hei := xMin._1, xMin._2; x < yMin._1; x++ {
+			for y := hei - 1; yMin._2 <= y; y-- {
+				if hori[y][x] {
+					hei = y
+				}
+			}
+			stairArea += hei - yMin._2
+		}
+		for y, hei := yMin._2, yMin._1; y < xMax._2; y++ {
+			for x := hei + 1; x <= xMax._1; x++ {
+				if vert[y][x] {
+					hei = x
+				}
+			}
+			stairArea += xMax._1 - hei
+		}
+		squareArea := (xMax._1 - xMin._1) * (yMax._2 - yMin._2)
+		fmt.Printf("Case #%d: %d\n", cid+1, squareArea-stairArea-polyArea)
 	}
 }

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

@@ -0,0 +1,2 @@
+Case #1: 0
+Case #2: 4

+ 27 - 0
2008/3/A/utils.go

@@ -0,0 +1,27 @@
+package main
+
+// Pair ...
+type Pair struct {
+	_1 int
+	_2 int
+}
+
+func minInt(nums ...int) int {
+	min := nums[0]
+	for i := 1; i < len(nums); i++ {
+		if nums[i] < min {
+			min = nums[i]
+		}
+	}
+	return min
+}
+
+func maxInt(nums ...int) int {
+	max := nums[0]
+	for i := 1; i < len(nums); i++ {
+		if max < nums[i] {
+			max = nums[i]
+		}
+	}
+	return max
+}