본문 바로가기
백준 알고리즘/브루트포스

백준 1018번 C++

by paysmile 2019. 2. 4.

#include <iostream>

#include <algorithm>

#include <string>

using namespace std;


const int MAX = 51;

int m, n;

string  arr[MAX];

string whitestart[8] = { { "WBWBWBWB" },{ "BWBWBWBW" },{ "WBWBWBWB" },{ "BWBWBWBW" },{ "WBWBWBWB" },{ "BWBWBWBW" },{ "WBWBWBWB" },{ "BWBWBWBW" }};

string blackstart[8] = { { "BWBWBWBW" },{ "WBWBWBWB" },{ "BWBWBWBW" },{ "WBWBWBWB" },{ "BWBWBWBW" },{ "WBWBWBWB" },{ "BWBWBWBW" },{ "WBWBWBWB" } };


int calwhite(int x,int y) {

int counts = 0;


for (int i = x; i < x + 8; i++) {

for (int j = y; j < y + 8; j++) {

if (whitestart[i - x][j - y] != arr[i][j])

counts += 1;

}

}

return counts;

}

int calblack(int x, int y) {

int counts = 0;


for (int i = x; i < x + 8; i++) {

for (int j = y; j < y + 8; j++) {

if (blackstart[i - x][j - y] != arr[i][j])

counts += 1;

}

}

return counts;

}


int calcolor() {

int mincounts = 987654321;


for (int x = 0; x <= n - 8; x++) {

for (int y = 0; y <= m - 8; y++) {

mincounts = min(mincounts, min(calwhite(x, y), calblack(x, y)));

}

}

return mincounts;

}


int main(void) {

cin >> n >> m;

for (int i = 0; i < n; i++) {

cin >> arr[i];

}

cout << calcolor();

return 0;

}


'백준 알고리즘 > 브루트포스' 카테고리의 다른 글

백준 15686번 C++  (0) 2019.04.13
백준 14502번 C++  (0) 2019.04.09
백준 14889번 C++  (0) 2019.01.28
백준 14888번 C++  (0) 2019.01.28
백준 14500번 C++  (0) 2019.01.27