-
Notifications
You must be signed in to change notification settings - Fork 0
/
1018.cpp
45 lines (37 loc) · 866 Bytes
/
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
42
43
44
45
#include <cstdio>
char board[50][50];
int have_to_redraw(int x, int y) {
int i, j, cnt1 = 0, cnt2 = 0;
for(j=0;j<8;j++) {
for(i=0;i<8;i++) {
if((i+j)%2==0) {
if(board[x+i][y+j]=='B')
cnt1++;
else
cnt2++;
}
else {
if(board[x+i][y+j]=='W')
cnt1++;
else
cnt2++;
}
}
}
return (cnt1<cnt2) ? cnt1 : cnt2;
}
int main() {
int N, M, i, j, temp, min = 64;
scanf("%d %d",&N,&M);
for(i = 0; i < N; i++) {
scanf("%s", board[i]);
}
for(i=0;i<N-7;i++) {
for(j=0;j<M-7;j++) {
temp = have_to_redraw(i,j);
min = (min > temp) ? temp : min;
}
}
printf("%d",min);
return 0;
}