🐣 알고리즘 삐약/💻 백준 삐약
94 삐약 : 백준 2630 | 색종이 만들기 [바킹독| 재귀 |JAVA]
우주수첩
2024. 9. 11. 00:14
728x90
https://www.acmicpc.net/problem/2630
package BKD_0x0B_Recursion;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class BOJ_2630 {
static int[][] input;
static int white, blue =0;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
input = new int[n][n];
// 배열 입력값
for(int i=0;i<n;i++){
st = new StringTokenizer(br.readLine());
for(int j=0;j<n;j++){
input[i][j] = Integer.parseInt(st.nextToken());
}
}
func(n,0,0);
System.out.println(white);
System.out.println(blue);
}
// 시작점 a, b 한 변의 길이 n
static void func(int n, int a, int b){
if(check(n,a,b)){
int val = input[a][b];
if(val == 0 ) white ++;
if(val == 1) blue++;
return;
}
int newN = n/2;
for(int i=a;i<a+n;i+=newN){
for(int j=b;j<b+n;j+=newN){
func(newN,i,j);
}
}
}
// 한 변의 길이 , 시작점 a,b
static boolean check(int n, int a, int b){
int init = input[a][b];
for(int i=a;i<a+n;i++){
for(int j=b;j<b+n;j++){
if(init != input[i][j]) {
return false;
}
}
}
return true;
}
}
2024.09.10 - [🐣 알고리즘 삐약/💻 백준 삐약] - 93 삐약 : 백준 1780| 종이의 개수 [바킹독| 재귀 |JAVA]
93 삐약 : 백준 1780| 종이의 개수 [바킹독| 재귀 |JAVA]
https://www.acmicpc.net/problem/1780 package BKD_0x0B_Recursion;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.util.StringTokenizer;public class BOJ_1780 { static int[][] input; static int minus, zero
dusty-wznt.tistory.com
위 포스팅과 풀이가 같다
728x90