Browse Source

Add some comment

dengxinyi 6 năm trước cách đây
mục cha
commit
dc4d7efeed
1 tập tin đã thay đổi với 8 bổ sung7 xóa
  1. 8 7
      2017/Qualification/D/main.go

+ 8 - 7
2017/Qualification/D/main.go

@@ -10,6 +10,7 @@ var N int
 var row, col []bool
 var diag1, diag2 []bool
 
+// < 0 means orignal solution, > 0 means new solution
 var crossSol, plusSol [][]int = make([][]int, MAXN), make([][]int, MAXN)
 
 func placeCrosses() {
@@ -23,15 +24,15 @@ func placeCrosses() {
 			}
 			crossSol[i][j] = 1
 			col[j] = true
-			break
+			break // Important
 		}
 	}
 }
 
-func placePluses() (points int) {
+func placePluses() (points int) { // It's important to figure out the state while placing pluses.
 	ds := make([]int, 0)
 	for i := 0; i < N-1; i++ {
-		ds = append(ds, i)
+		ds = append(ds, i) // Start alternately from both ends
 		ds = append(ds, 2*N-i-2)
 	}
 	ds = append(ds, N-1)
@@ -69,7 +70,7 @@ func main() {
 		var M int
 		fmt.Scan(&N, &M)
 
-		row = make([]bool, MAXN)
+		row = make([]bool, MAXN) // Init all state
 		col = make([]bool, MAXN)
 		diag1 = make([]bool, 2*MAXN-1)
 		diag2 = make([]bool, 2*MAXN-1)
@@ -83,11 +84,11 @@ func main() {
 			var r, c int
 			fmt.Scan(&ch, &r, &c)
 			r, c = r-1, c-1
-			if ch != "+" {
+			if ch != "+" { // Is not bishop
 				crossSol[r][c] = -1
 				row[r], col[c] = true, true
 			}
-			if ch != "x" {
+			if ch != "x" { // Is not rook
 				plusSol[r][c] = -1
 				diag1[r+c], diag2[r-c+N-1] = true, true
 			}
@@ -110,7 +111,7 @@ func main() {
 			for j := 0; j < N; j++ {
 				if 0 < crossSol[i][j] || 0 < plusSol[i][j] {
 					var ch byte
-					if plusSol[i][j] != 0 && crossSol[i][j] != 0 {
+					if plusSol[i][j] != 0 && crossSol[i][j] != 0 { // != 0 means original sol add new sol
 						ch = 'o'
 					} else if plusSol[i][j] != 0 {
 						ch = '+'