diff --git "a/MINWOOK/15683-\354\234\244\353\257\274\354\232\261.java" "b/MINWOOK/15683-\354\234\244\353\257\274\354\232\261.java" new file mode 100644 index 0000000..dbf4017 --- /dev/null +++ "b/MINWOOK/15683-\354\234\244\353\257\274\354\232\261.java" @@ -0,0 +1,173 @@ +import java.util.ArrayList; +import java.util.Scanner; + +public class Solution { + + private static final int UP = 0; + private static final int RIGHT = 1; + private static final int DOWN = 2; + private static final int LEFT = 3; + private static final int WALL = 6; + private static final int MAX = 4; + + public static int[][] office; + public static int n, m; + public static int min = Integer.MAX_VALUE; + + public static class CCTV { + + int x, y; + int type; + boolean[] directionList; + + public CCTV(int x, int y, int type) { + + this.x = x; + this.y = y; + this.type = type; + this.directionList = new boolean[MAX]; + this.initialize(); + } + + public void initialize() { + + if (this.type == 1) { + + directionList[UP] = true; + } else if (this.type == 2) { + + directionList[LEFT] = true; + directionList[RIGHT] = true; + } else if (this.type == 3) { + + directionList[UP] = true; + directionList[RIGHT] = true; + } else if (this.type == 4) { + + directionList[LEFT] = true; + directionList[UP] = true; + directionList[RIGHT] = true; + } else { + + for (int i = 0; i < this.directionList.length; i++) + directionList[i] = true; + } + } + + public void rotate() { + + boolean temp = this.directionList[LEFT]; + this.directionList[LEFT] = this.directionList[DOWN]; + this.directionList[DOWN] = this.directionList[RIGHT]; + this.directionList[RIGHT] = this.directionList[UP]; + this.directionList[UP] = temp; + } + + public boolean[][] inspection(boolean[][] isInspected) { + + boolean[][] result = new boolean[n][m]; + + for (int i = 0; i < n; i++) + for (int j = 0; j < m; j++) + result[i][j] = isInspected[i][j]; + + if (this.directionList[0]) { + for (int i = x; i >= 0; i--) { + if (office[i][y] == WALL) + break; + + result[i][y] = true; + } + } + if (this.directionList[1]) { + for (int i = y; i < m; i++) { + if (office[x][i] == WALL) + break; + + result[x][i] = true; + } + } + if (this.directionList[2]) { + for (int i = x; i < n; i++) { + if (office[i][y] == WALL) + break; + + result[i][y] = true; + } + } + if (this.directionList[3]) { + for (int i = y; i >= 0; i--) { + if (office[x][i] == WALL) + break; + + result[x][i] = true; + } + } + + return result; + } + } + + public static void main(String[] args) { + + @SuppressWarnings("resource") + Scanner sc = new Scanner(System.in); + + n = sc.nextInt(); + m = sc.nextInt(); + + office = new int[n][m]; + ArrayList cctvList = new ArrayList(); + boolean[][] isInspected = new boolean[n][m]; + + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + + int input = sc.nextInt(); + if (input == WALL) { + isInspected[i][j] = true; + } + office[i][j] = input; + if (input > 0 && input != WALL) { + cctvList.add(new CCTV(i, j, input)); + } + } + } + + solution(cctvList, isInspected, 0); + System.out.println(min); + } + + public static void solution(ArrayList cctvList, boolean[][] isInspected, int index) { + + if (index == cctvList.size()) { + + int sum = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (!isInspected[i][j]) { + sum++; + } + + } + } + + if (sum < min) { + min = sum; + } + return; + } + + CCTV cctv = cctvList.get(index); + + for (int i = 0; i < 4; i++) { + + boolean[][] temp = cctv.inspection(isInspected); + solution(cctvList, temp, index + 1); + + cctv.rotate(); + } + + } + +} diff --git "a/MINWOOK/2583-\354\234\244\353\257\274\354\232\261.java" "b/MINWOOK/2583-\354\234\244\353\257\274\354\232\261.java" new file mode 100644 index 0000000..c4a8b57 --- /dev/null +++ "b/MINWOOK/2583-\354\234\244\353\257\274\354\232\261.java" @@ -0,0 +1,100 @@ + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Scanner; + +public class Main { + + private static final int BLOCKED = -1; + private static final int UNVISITED = 0; + private static final int VISITED = 1; + + public static int m, n, k; + public static int[][] coordinate; + public static boolean[][] isVisited; + public static ArrayList areaList; + public static int area = 0; + + public static void main(String[] args) { + // TODO Auto-generated method stub + + Scanner sc = new Scanner(System.in); + + m = sc.nextInt(); + n = sc.nextInt(); + k = sc.nextInt(); + coordinate = new int[m][n]; + isVisited = new boolean[m][n]; + areaList = new ArrayList(); + + while (k > 0) { + + boolean[][] isVisited = new boolean[m][n]; + int i = sc.nextInt(); + int j = sc.nextInt(); + int x = sc.nextInt(); + int y = sc.nextInt(); + dfs(j, i, y, x, isVisited); + k--; + } + + int count = 0; + for (int i = 0; i < m; i++) { + for (int j = 0; j < n; j++) { + + if (coordinate[i][j] != BLOCKED && !isVisited[i][j]) { + + solution(i, j); + areaList.add(area); + area = 0; + count++; + } + } + } + + Collections.sort(areaList); + System.out.println(count); + for(int i : areaList) + System.out.print(i + " "); + + } + + public static void dfs(int i, int j, int x, int y, boolean[][] isVisited) { + + coordinate[i][j] = BLOCKED; + isVisited[i][j] = true; + + if (i + 1 < x && !isVisited[i + 1][j]) { + + dfs(i + 1, j, x, y, isVisited); + } + if (j + 1 < y && !isVisited[i][j + 1]) { + + dfs(i, j + 1, x, y, isVisited); + } + } + + public static void solution(int x, int y) { + + area++; + isVisited[x][y] = true; + coordinate[x][y] = VISITED; + + if (x + 1 < m && coordinate[x + 1][y] != BLOCKED && !isVisited[x + 1][y]) { + + solution(x + 1, y); + } + if (x - 1 >= 0 && coordinate[x - 1][y] != BLOCKED && !isVisited[x - 1][y]) { + + solution(x - 1, y); + } + if (y + 1 < n && coordinate[x][y + 1] != BLOCKED && !isVisited[x][y + 1]) { + + solution(x, y + 1); + } + if (y - 1 >= 0 && coordinate[x][y - 1] != BLOCKED && !isVisited[x][y - 1]) { + + solution(x, y - 1); + } + } +}