Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0da6e94

Browse files
committed
고다혜: [BOJ] 1882 쿼드트리_241217
1 parent e4985b0 commit 0da6e94

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

‎BOJ/1000-5000번/DH_1992.java‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import java.io.*;
2+
3+
/*
4+
* 쿼드트리
5+
*/
6+
7+
public class DH_1992 {
8+
static int[][] arr;
9+
public static void main(String[] args) throws Exception {
10+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
11+
12+
int N = Integer.parseInt(br.readLine());
13+
arr = new int[N][N];
14+
15+
for(int r = 0; r < N; r++) {
16+
String s = br.readLine();
17+
18+
for(int c = 0; c < N; c++) {
19+
arr[r][c] = s.charAt(c) - '0';
20+
}
21+
}
22+
23+
int length = N;
24+
25+
String str = func(0, 0, length);
26+
System.out.println(str);
27+
}
28+
29+
static String func(int r, int c, int l) {
30+
String s = "";
31+
32+
int sum = 0;
33+
for(int sr = r; sr < r + l; sr++) {
34+
for(int sc = c; sc < c + l; sc++) {
35+
sum += arr[sr][sc];
36+
}
37+
}
38+
39+
if(sum == 0) s += "0";
40+
else if(sum == l * l) s += "1";
41+
else {
42+
int nl = l >> 1;
43+
s += "(";
44+
s += func(r, c, nl); // 왼쪽 위
45+
s += func(r, c + nl, nl); // 오른쪽 위
46+
s += func(r + nl, c, nl); // 왼쪽 아래
47+
s += func(r + nl, c + nl, nl); // 오른쪽 아래
48+
s += ")";
49+
}
50+
return s;
51+
}
52+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /