https://www.acmicpc.net/problem/1018
1018번: 체스판 다시 칠하기
첫째 줄에 N과 M이 주어진다. N과 M은 8보다 크거나 같고, 50보다 작거나 같은 자연수이다. 둘째 줄부터 N개의 줄에는 보드의 각 행의 상태가 주어진다. B는 검은색이며, W는 흰색이다.
www.acmicpc.net
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
// 검은색 먼저 흰색 먼저
int arr[55][55], board1[8][8], board2[8][8];
int main(){
int n,m, result = 64;
int chk1=0, chk2=0;
cin >> n>> m;
for(int i=0;i<n;i++){
string s;
cin>>s;
for(int j=0;j<m;j++){
if (s[j] == 'B') arr[i][j] = 1;
else arr[i][j] = 0;
}
}
for(int i=0;i<8;i++) for(int j=0;j<8;j++){
board1[i][j] = (i+j+1)%2;
board2[i][j] = (i+j)%2;
}
// 확 인
// for(int i=0;i<n;i++){
// for(int j=0;j<m;j++){
// cout<<arr[i][j]<<" ";
// }
// cout<<endl;
// }
// for(int i=0;i<8;i++){
// for(int j=0;j<8;j++){
// cout<<board1[i][j]<<" ";
// }
// cout<<endl;
// }
for(int i=0;i+8<=n;i++){
for(int j=0;j+8<=m;j++){
chk1 = 0; chk2 = 0;
// board1,2 비교
for(int k=0;k<8;k++){
for(int l=0;l<8;l++){
if(arr[i+k][j+l] != board1[k][l]) chk1++;
if(arr[i+k][j+l] != board2[k][l]) chk2++;
}
}
result = min(min(chk1, chk2), result);
}
}
cout<<result;
}
'자기개발👨💻 > 코딩 알고리즘' 카테고리의 다른 글
[C++] 백준 11399 ATM //<pairArray> (0) | 2022.04.06 |
---|---|
[C++] 백준 1182 부분수열의 합 (0) | 2022.03.30 |
[C++] 백준 1436 영화감독 숌 (0) | 2022.03.23 |
[C++] 백준 11279최대힙, 1927최소힙 (0) | 2022.03.18 |
[C++] 백준 1158 요세푸스 문제 //<queue> (0) | 2022.03.18 |
[C++] 백준 11651 // <vector><map> (0) | 2022.03.16 |