Skip to content

Commit a167f1c

Browse files
committed
0914
1 parent efc8e12 commit a167f1c

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-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/BOJ2667/BOJ2667.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/BOJ2667/src/Main.java

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import java.io.BufferedReader;
2+
import java.io.IOException;
3+
import java.io.InputStreamReader;
4+
import java.util.ArrayList;
5+
import java.util.List;
6+
import java.util.StringTokenizer;
7+
8+
public class Main {
9+
public static void main(String[] args) throws IOException {
10+
11+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
12+
StringTokenizer st = new StringTokenizer(br.readLine());
13+
int n = Integer.parseInt(st.nextToken());
14+
ArrayList<Integer>[] MAP = new ArrayList[n];
15+
int [][] vistied = new int[n][n];
16+
for (int i = 0; i < n; i++) {
17+
MAP[i] = new ArrayList<>();
18+
}
19+
20+
21+
for (int i = 0; i < n; i++) {
22+
st = new StringTokenizer(br.readLine());
23+
24+
String input = st.nextToken();
25+
for (int j = 0; j < input.length(); j++) {
26+
MAP[i].add(Integer.parseInt(String.valueOf(input.charAt(j))));
27+
}
28+
}
29+
int MapCnt=0;
30+
for(int i=0;i<n;i++){
31+
for(int j=0; j<n;j++){
32+
if(MAP[i].get(j)==1){
33+
if (vistied[i][j]==0){
34+
vistied[i][j]=1;
35+
int count=Find(MAP,vistied,i,j,n,1);
36+
MapCnt+=1;
37+
System.out.println(count);
38+
}
39+
40+
}
41+
}
42+
}
43+
44+
}
45+
46+
public static int Find(ArrayList<Integer>[] MAP,int[][] vistied, int i, int j, int n, int count) {
47+
int [] dc={0,0,-1,1};
48+
int [] dr={1,-1,0,0};
49+
for(int k=0;k<4;k++){
50+
int nc=i+dc[k];
51+
int nr=j+dr[k];
52+
if((0<=nc&&nc<n)&&(0<=nr&&nr<n)){
53+
if (MAP[nc].get(nr)==1){
54+
if(vistied[nc][nr]==0){
55+
vistied[nc][nr]=1;
56+
count+=1;
57+
Find(MAP,vistied,nc,nr,n,count);
58+
vistied[nc][nr]=0;
59+
}
60+
61+
}
62+
}
63+
64+
}
65+
return count;
66+
67+
}
68+
}

0 commit comments

Comments
 (0)