브루투포스로 풀었따. 고민하다가 생각이 나지 않아 인터넷에 검색해서 풀었다.
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include<queue>
using namespace std;
string WB[8] = {
"WBWBWBWB",
"BWBWBWBW",
"WBWBWBWB",
"BWBWBWBW",
"WBWBWBWB",
"BWBWBWBW",
"WBWBWBWB",
"BWBWBWBW"
};
string BW[8] = {
"BWBWBWBW",
"WBWBWBWB",
"BWBWBWBW",
"WBWBWBWB",
"BWBWBWBW",
"WBWBWBWB",
"BWBWBWBW",
"WBWBWBWB"
};
string board[50];
int wbcomp(int x, int y) {
int cnt = 0;
for (int i = 0; i < 8; i++)
for (int k = 0; k < 8; k++) {
if (board[x + i][y + k] != WB[i][k])
cnt++;
}
return cnt;
}
int bwcomp(int x, int y) {
int cnt = 0;
for(int i =0; i < 8; i++)
for (int k = 0; k < 8; k++) {
if (board[x + i][y + k] != BW[i][k])
cnt++;
}
return cnt;
}
int main() {
pair<int, int>p1;
int min_value = 65;
int tmp;
cin >> p1.first >> p1.second;
for (int i = 0; i < p1.first; i++)
cin >> board[i];
for (int i = 0; i + 8 <= p1.first; i++) {
for (int k = 0; k + 8 <= p1.second; k++) {
tmp = min(wbcomp(i, k), bwcomp(i, k));
if(min_value > tmp)
min_value = tmp;
}
}
cout << min_value;
return 0;
}