-
Notifications
You must be signed in to change notification settings - Fork 0
/
BOJ_1018.cpp
69 lines (57 loc) · 1.47 KB
/
BOJ_1018.cpp
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
#include<iostream>
#include<string>
#include<vector>
#define INT_MAX 0x7fffffff;
using namespace std;
int diff(string str1, string str2) {
int count = 0;
for (int i = 0; i < 8; i++) {
if (str1[i] != str2[i]) count++;
}
return count;
}
string cut(string str, int offset) {
string result;
for (int i = offset; i < offset + 8; i++) {
result += str[i];
}
return result;
}
int main(void) {
string pat1 = "WBWBWBWB";
string pat2 = "BWBWBWBW";
vector<string> board;
int n, m, MIN = INT_MAX;
cin >> n >> m;
for (int i = 0; i < n; i++) {
string input;
cin >> input;
board.push_back(input);
}
for (int i = 0; i <= n - 8; i++) {
for (int j = 0; j <= m - 8; j++) {
int cnt = 0;
for (int z = 0; z < 8; z++) {
string c = cut(board[i + z], j);
if (z % 2 == 0) cnt += diff(c, pat1);
else cnt += diff(c, pat2);
}
MIN = MIN < cnt ? MIN : cnt;
cnt = 0;
}
}
for (int i = 0; i <= n - 8; i++) {
for (int j = 0; j <= m - 8; j++) {
int cnt = 0;
for (int z = 0; z < 8; z++) {
string c = cut(board[i + z], j);
if (z % 2 == 0) cnt += diff(c, pat2);
else cnt += diff(c, pat1);
}
MIN = MIN < cnt ? MIN : cnt;
cnt = 0;
}
}
cout << MIN << endl;
return 0;
}