[BOJ] 1018 체스판 다시 칠하기

Time Lapse : 16min 34sec

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
#include <iostream>
#include <memory.h>
#include <vector>
using namespace std;
int M, N;
char MAP[50][50];
char CMP[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'}};
int answer=987654321;

void compare(int x,int y){
int cnt = 0;
for (int i = 0; i < 8; i++)
for (int j = 0; j < 8; j++)
if (CMP[i][j] != MAP[y + i][x + j])
++cnt;
if(cnt>=32)
cnt = 64-cnt;
answer = answer>cnt ? cnt : answer;
return ;
}

int main(void){
cin>>M>>N;
for(int i=0;i<M;i++)
for(int j=0;j<N;j++)
cin>>MAP[i][j];

for(int i=0;i<=M-8;i++)
for(int j=0;j<=N-8;j++)
compare(j,i);

cout<<answer<<endl;
return 0;
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/07/23/PS/BOJ/1018/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.