-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1018.cpp
69 lines (64 loc) · 1.56 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
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
char brd1[9][9] = { { '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' },
{ 'W','B','W','B','W','B','W','B' } };
char brd2[9][9] = { { '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' } };
char board[70][70];
char tmp[9][9];
void tmpcpy(int i, int j)
{
for (int a = i; a < i + 8; a++)
for (int b = j; b < j + 8; b++)
tmp[a - i][b - j] = board[a][b];
}
int cmpboard()
{
int cnt1 = 0, cnt2 = 0, ans = 0;
for (int i = 0; i < 8; i++)
{
for (int j = 0; j < 8; j++)
{
if (tmp[i][j] != brd1[i][j])
cnt1 += 1;
if (tmp[i][j] != brd2[i][j])
cnt2 += 1;
}
}
ans = cnt1 > cnt2 ? cnt2 : cnt1;
return (ans);
}
int main(void)
{
int N, M;
int cnt, ans = 64;
scanf("%d %d", &N, &M);
getchar();
for (int i = 0; i < N; i++)
{
scanf("%s", board[i]);
getchar();
}
for (int i = 0; i < N - 7; i++)
{
for (int j = 0; j < M - 7; j++)
{
tmpcpy(i, j);
cnt = cmpboard();
ans = ans > cnt ? cnt : ans;
}
}
printf("%d\n", ans);
}