-
Notifications
You must be signed in to change notification settings - Fork 0
/
Chess_1018.java
45 lines (38 loc) · 1.14 KB
/
Chess_1018.java
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
package stepbystep;
import java.io.*;
import java.util.*;
public class Chess_1018 {
final static String[] chess = { "WBWBWBWB", "BWBWBWBW", "WBWBWBWB", "BWBWBWBW",
"WBWBWBWB", "BWBWBWBW", "WBWBWBWB", "BWBWBWBW" };
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringTokenizer st = new StringTokenizer(br.readLine());
int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());
String [] s = new String[N];
for (int i=0; i<N; i++) { // N*M ¹è¿À» ÀԷ¹޴´Ù
s[i] = br.readLine();
}
int result = Integer.MAX_VALUE;
for (int i=0; i<=N-8; i++) {
for (int j=0; j<=M-8; j++) {
int cnt = 0;
for (int k=0; k<8; k++) {
String temp = s[i+k].substring(j, j+8);
for (int l=0; l<8; l++) {
if (temp.charAt(l) == chess[k].charAt(l)) {
cnt++;
}
}
}
if (cnt >= 32) cnt = 64-cnt;
result = Math.min(result, cnt);
}
}
bw.write(result + "\n");
bw.flush();
br.close();
bw.close();
}
}