Algorithm/Cases-BOJ
체스판 다시 칠하기
Xi_kor
2021. 4. 14. 19:12
칠할 수 있는 모든 경우를 만들어서 비교해주었다.
#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
char arr[60][60];
int cnt=2147000000;
char wstart[8][8]={
{'W', 'B', 'W', 'B', 'W', 'B', 'W', 'B'},
{'B', 'W', 'B', 'W', 'B', 'W', 'B', 'W'},
{'W', 'B', 'W', 'B', 'W', 'B', 'W', 'B'},
{'B', 'W', 'B', 'W', 'B', 'W', 'B', 'W'},
{'W', 'B', 'W', 'B', 'W', 'B', 'W', 'B'},
{'B', 'W', 'B', 'W', 'B', 'W', 'B', 'W'},
{'W', 'B', 'W', 'B', 'W', 'B', 'W', 'B'},
{'B', 'W', 'B', 'W', 'B', 'W', 'B', 'W'}
};
char bstart[8][8]={
{'B', 'W', 'B', 'W', 'B', 'W', 'B', 'W'},
{'W', 'B', 'W', 'B', 'W', 'B', 'W', 'B'},
{'B', 'W', 'B', 'W', 'B', 'W', 'B', 'W'},
{'W', 'B', 'W', 'B', 'W', 'B', 'W', 'B'},
{'B', 'W', 'B', 'W', 'B', 'W', 'B', 'W'},
{'W', 'B', 'W', 'B', 'W', 'B', 'W', 'B'},
{'B', 'W', 'B', 'W', 'B', 'W', 'B', 'W'},
{'W', 'B', 'W', 'B', 'W', 'B', 'W', 'B'}
};
void compareb(int x, int y){
int val=0;
for(int i=0; i<8; i++){
for(int j=0; j<8; j++){
if(arr[x+i][y+j]!=bstart[i][j]) val++;
}
}
if(val<cnt) cnt=val;
}
void comparew(int x, int y){
int val=0;
for(int i=0; i<8; i++){
for(int j=0; j<8; j++){
if(arr[x+i][y+j]!=wstart[i][j]) val++;
}
}
if(val<cnt) cnt=val;
}
int main(){
int n, m;
cin>>n>>m;
for(int i=0; i<n; i++){
for(int j=0; j<m; j++){
cin>>arr[i][j];
}
}
for(int i=0; i<=n-8; i++){
for(int j=0; j<=m-8; j++){
compareb(i, j);
comparew(i, j);
}
}
cout<<cnt;
return 0;
}