문제 출처: https://www.acmicpc.net/problem/1780
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Main { private static int[][] arr; private static int[] num = new int[3]; // -1, 0 ,1 public static void main(String[] args) throws NumberFormatException, IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); int N = Integer.parseInt(reader.readLine()); arr = new int[N][N]; for(int i=0 ; i<N ; i++){ StringTokenizer tokenizer = new StringTokenizer(reader.readLine()); for(int j=0 ; j<N ; j++){ arr[i][j] = Integer.parseInt(tokenizer.nextToken()); } } cut(N, 0, 0); for(int i=0 ; i<3 ; i++) System.out.println(num[i]); } public static boolean equal(int size, int startX, int startY){ int target = arr[startY][startX]; for(int i=startY ; i<startY+size ; i++){ for(int j=startX ; j<startX+size ; j++){ if(target != arr[i][j]){ return false; } } } num[target+1]++; return true; } public static void cut(int size, int startX, int startY){ if(equal(size, startX, startY)) return; for(int i=0 ; i<3 ; i++) for(int j=0 ; j<3 ; j++) cut(size/3, startX + j*(size/3), startY + i*(size/3)); } } | cs |
'Algorithm' 카테고리의 다른 글
백준 1940번: 주몽 (0) | 2018.09.23 |
---|---|
백준 1834번: 나머지와 몫이 같은 수 (0) | 2018.09.22 |
백준 1992번: 쿼드트리 (0) | 2018.08.08 |
Divide and Conquer (분할정복법) (0) | 2018.08.07 |
백준 2504번: 괄호의 값 (0) | 2018.08.01 |