Skip to content

Commit 93debb8

Browse files
committed
0926
1 parent d4e8a98 commit 93debb8

File tree

3 files changed

+81
-0
lines changed

3 files changed

+81
-0
lines changed

.idea/modules.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

BOJ/silver/BOJ1303/BOJ1303.iml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7+
</content>
8+
<orderEntry type="inheritedJdk" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
</component>
11+
</module>

BOJ/silver/BOJ1303/src/Main.java

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import java.io.BufferedReader;
2+
import java.io.IOException;
3+
import java.io.InputStreamReader;
4+
import java.util.StringTokenizer;
5+
6+
public class Main {
7+
static int N;
8+
static int M;
9+
static int[][] visitied;
10+
static int[] dc = {-1, 1, 0, 0};
11+
static int[] dr = {0, 0, 1, -1};
12+
static char[][] field;
13+
static int count=0;
14+
public static void main(String[] args) throws IOException {
15+
16+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
17+
StringTokenizer st = new StringTokenizer(br.readLine());
18+
N = Integer.parseInt(st.nextToken());
19+
M = Integer.parseInt(st.nextToken());
20+
field = new char[M][N];
21+
visitied = new int[M][N];
22+
int White=0;
23+
int Bule=0;
24+
for (int i = 0; i < M; i++) {
25+
String s = br.readLine();
26+
for (int j = 0; j < N; j++) {
27+
field[i][j] = s.charAt(j);
28+
}
29+
}
30+
for (int i = 0; i < M; i++) {
31+
for (int j = 0; j < N; j++) {
32+
if (visitied[i][j] == 0) {
33+
visitied[i][j] = 1;
34+
count = 1;
35+
DFS(i, j, field[i][j]);
36+
37+
if(field[i][j]=='W'){
38+
White+=Math.pow(count,2);
39+
}else{
40+
Bule+=Math.pow(count,2);
41+
}
42+
43+
}
44+
}
45+
}
46+
System.out.println(White+" "+Bule);
47+
48+
}
49+
50+
private static void DFS(int col, int row, char pattern) {
51+
for (int i = 0; i < 4; i++) {
52+
int cc = col + dc[i];
53+
int cr = row + dr[i];
54+
if (0 <= cc && cc < M && 0 <= cr && cr < N) {
55+
if (visitied[cc][cr] == 0 && field[cc][cr] == pattern){
56+
visitied[cc][cr] = 1;
57+
count++;
58+
DFS(cc, cr, pattern);
59+
}
60+
61+
62+
}
63+
64+
}
65+
66+
67+
68+
}
69+
}

0 commit comments

Comments
 (0)