-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1018.js
69 lines (58 loc) · 1.39 KB
/
1018.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
const { SourceMap } = require("module");
var readline = require("readline");
var r = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
let input = [];
r.on("line", function (line) {
input.push(line);
}).on("close", function () {
main(input);
process.exit();
});
function main(input){
let [NM, ...board] = input;
const [N, M] = NM.split(" ").map(Number);
board = board.map(val => val.split(""));
let result = Infinity;
for(let i = 0 ; i <= N - 8; i++) {
for(let j = 0 ; j <= M - 8; j++) {
let val = countChange(i,j,board);
if(val < result){
result = val;
}
}
}
console.log(result)
}
function countChange(x,y, board){
let fstW = 0;
let fstB = 0;
for(let i = x; i < x + 8; i++){
let temp;
if(i % 2 === 0){
temp = 'W';
}else{
temp = 'B';
}
for(let j = y; j < y + 8; j++){
if(board[i][j] === temp){
if(j % 2 === 0){
++fstW;
}else{
++fstB;
}
}else{
if(j % 2 ==! 0){
++fstW;
}else{
++fstB;
}
}
}
}
// console.log(fstB, fstW)
if(fstB > fstW) return fstW;
return fstB
}