-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1018.java
More file actions
67 lines (61 loc) · 1.87 KB
/
1018.java
File metadata and controls
67 lines (61 loc) · 1.87 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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
char Wstart[][]= {{'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 Bstart[][]= {{'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 TestChess(int i,int j,char[][] chess) {
int changeB=0,changeW=0;
char test[][];
test = Bstart.clone();
for(int x=i;x<i+8; x++){
for(int y=j; y<j+8; y++) {
if(chess[x][y]!=test[x-i][y-j])
changeB++;
}
}
test = Wstart.clone();
for(int x=i;x<i+8; x++){
for(int y=j; y<j+8; y++) {
if(chess[x][y]!=test[x-i][y-j])
changeW++;
}
}
return Math.min(changeW, changeB);
}
public static void main(String[] args)throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st= new StringTokenizer(br.readLine()," ");
Main Main = new Main();
int N=Integer.parseInt(st.nextToken());
int M=Integer.parseInt(st.nextToken());
char[][] chess = new char[N][M];
for(int i=0; i<N; i++)
chess[i]=br.readLine().toCharArray();
int min=2500;//최대값으로 설정 50*50
int result;
for(int i=0; i<=N-8; i++) {
for(int j=0; j<=M-8; j++) {
result=Main.TestChess(i, j, chess);
if(min>result)
min=result;
}
}
System.out.println(min);
}
}