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 f0ef9f1

Browse files
committed
이예진: [BOJ] 1992 쿼드트리_241217
1 parent bc13faa commit f0ef9f1

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

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

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import java.io.*;
2+
3+
//1<=N<=64
4+
//분할정복: 반복해서 작은영역을 탐색할 때는 `재귀`를 생각해보기
5+
public class YJ_1992 {
6+
static char[][] video;
7+
public static void main(String[] args) throws IOException {
8+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
9+
int n = Integer.parseInt(br.readLine());
10+
video = new char[n][n];
11+
for(int i=0; i<n; i++){
12+
String data = br.readLine();
13+
for(int j=0; j<n; j++){
14+
video[i][j] = data.charAt(j);
15+
}
16+
}
17+
18+
compress(0,0,n);
19+
System.out.println(sb.toString());
20+
}
21+
22+
static StringBuilder sb = new StringBuilder();
23+
static void compress(int x, int y, int size){
24+
if(check(x, y, size)){
25+
sb.append(video[x][y]);
26+
return;
27+
}
28+
sb.append("(");
29+
compress(x,y,size/2); //왼쪽위
30+
compress(x,y+size/2,size/2); //오른쪽위
31+
compress(x+size/2,y,size/2); //왼쪽아래
32+
compress(x+size/2,y+size/2,size/2); //오른쪽아래
33+
sb.append(")");
34+
}
35+
36+
static boolean check(int x, int y, int size){
37+
int value = video[x][y];
38+
for(int i=x; i<x+size; i++){
39+
for(int j=y; j<y+size; j++){
40+
if(value != video[i][j]){ //기준(0또는1)과 하나라도 틀리면 분할해야함
41+
return false;
42+
}
43+
}
44+
}
45+
return true;
46+
}
47+
}

0 commit comments

Comments
(0)

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