반응형
https://www.acmicpc.net/problem/1018
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
|
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
char arr_check1[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'}
};
char arr_check2[8][8] = {
{'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'}
};
int N, M;
char str[50][50];
int Solve() {
int MIn_value = 987654321;
for (int i = 0;i <= N - 8;i++) {
for (int j = 0;j <= M - 8;j++) {
int cnt1 = 0;
int cnt2 = 0;
int y_ = 0;
int x_ = 0;
for (int y = i ;y < i + 8;y++) {
x_ = 0;
for (int x = j;x < j + 8;x++) {
if (arr_check1[y_][x_] != str[y][x]) cnt1++;
x_++;
}
y_++;
}
y_ = 0;
for (int y = i;y < i + 8;y++) {
x_ = 0;
for (int x = j;x < j + 8;x++) {
if (arr_check2[y_][x_] != str[y][x]) cnt2++;
x_++;
}
y_++;
}
MIn_value = min(MIn_value, min(cnt1, cnt2));
}
}
return MIn_value;
}
int main(void) {
cin >> N >> M;
for (int i = 0;i < N;i++) {
for (int j = 0;j < M;j++) {
cin >> str[i][j];
}
}
cout << Solve();
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
반응형