-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathback_1018.cpp
More file actions
69 lines (59 loc) · 1.47 KB
/
back_1018.cpp
File metadata and controls
69 lines (59 loc) · 1.47 KB
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
#include <iostream>
using namespace std;
char **board;
int findDiff(int x, int y)
{
int BW_Cnt = 0;
int WB_Cnt = 0;
for (int i = x; i < x + 8; i++)
{
for (int j = y; j < y + 8; j++)
{
if ((i + j) % 2 == 0)
{
if (board[i][j] != 'B')
BW_Cnt++;
else
WB_Cnt++;
}
else
{
if (board[i][j] != 'W')
BW_Cnt++;
else
WB_Cnt++;
}
}
}
if (BW_Cnt > WB_Cnt)
return WB_Cnt;
else
return BW_Cnt;
}
int main()
{
cin.tie(NULL);
ios::sync_with_stdio(false);
int N, M;
cin >> N >> M;
board = new char *[N];
for (int i = 0; i < N; i++)
board[i] = new char[M];
for (int i = 0; i < N; i++)
for (int j = 0; j < M; j++)
cin >> board[i][j];
int min = -1;
for (int i = 0; i + 7 < N; i++)
{
for (int j = 0; j + 7 < M; j++)
{
int cnt = findDiff(i, j);
if (min == -1)
min = cnt;
else if (min > cnt)
min = cnt;
}
}
cout << min;
return 0;
}