-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1018.cpp
89 lines (74 loc) · 1.42 KB
/
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
using namespace std;
string WB[8] = {
"WBWBWBWB",
"BWBWBWBW",
"WBWBWBWB",
"BWBWBWBW",
"WBWBWBWB",
"BWBWBWBW",
"WBWBWBWB",
"BWBWBWBW"
};
string BW[8] = {
"BWBWBWBW",
"WBWBWBWB",
"BWBWBWBW",
"WBWBWBWB",
"BWBWBWBW",
"WBWBWBWB",
"BWBWBWBW",
"WBWBWBWB"
};
string board[50];
int WB_cnt(int x, int y)
{
int cnt = 0;
for(int i = 0; i < 8; i++)
{
for(int j = 0; j < 8; j++)
{
if(board[x+i][y+j] != WB[i][j])
cnt++;
}
}
return cnt;
}
int BW_cnt(int x, int y)
{
int cnt = 0;
for(int i = 0; i < 8; i++)
{
for(int j = 0; j < 8; j++)
{
if(board[x+i][y+j] != BW[i][j])
cnt++;
}
}
return cnt;
}
int main(void){
ios_base::sync_with_stdio(false); cin.tie(NULL);
int size[2];
int cnt;
int min_val = 12345;
int n,m;
cin >> n >> m;
for(int i=0; i<n; i++){
cin >> board[i];
}
for(int i=0; i + 8 <= n; i++){
for(int j=0; j + 8 <= m; j++){
int tmp;
tmp = min(WB_cnt(i,j),BW_cnt(i,j));
if(tmp < min_val){
min_val = tmp;
}
}
}
cout << min_val;
return 0;
}