Notice
Recent Posts
문제 풀이 및 개발 공간
[백준] 1992번 쿼드트리 (silver 1 본문
import java.io.*;
import java.util.*;
public class Main{
static StringBuilder sb=new StringBuilder();
static int[][] map;
public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int n=Integer.valueOf(br.readLine());
map=new int[n+1][n+1];
for(int i=1; i<=n; i++){
String a=br.readLine();
for(int j=1; j<=n; j++){
map[i][j]=a.charAt(j-1)-'0';
}
}
divide(1,n, 1,n,n);
System.out.println(sb.toString());
}
public static void divide(int cols, int cole , int rows, int rowe,int length ){
int temp=map[rows][cols];
int tlength=length/2;
boolean same=true;
for(int i=rows; i<=rowe; i++){
for(int j=cols; j<=cole; j++){
if(map[i][j]!=temp){
same=false;
break;
}
}
}
//영역마다 다 똑같으면 해당 숫자, 아니면 분할해서 나눠서 들어가기.
if(same){
if(temp==1){
sb.append("1");
}
else{
sb.append("0");
}
}
//영역 나눌때 조심.
else{
sb.append("(");
divide(cols, cols+tlength-1, rows, rows+tlength-1 , tlength);
divide(cols+tlength, cole, rows, rows+tlength-1 ,tlength);
divide(cols, cols+tlength-1, rows+tlength, rowe,tlength);
divide(cols+tlength, cole, rows+tlength, rowe,tlength);
sb.append(")");
}
}
}
'백준공부 > java' 카테고리의 다른 글
[백준] 1303번 전쟁 - 전투 (silver 1 (0) | 2024.09.03 |
---|---|
[백준] 1213번 팰린드롬 만들기 (silver 3 (0) | 2024.09.03 |
[백준] 1057번 토너먼트 (silver 4 (0) | 2024.09.03 |
[백준] 1343번 폴리오미노 (silver 5 (0) | 2024.09.03 |
[백준] 4179번 불! (gold 3 (0) | 2024.06.27 |