From 5405dd5457b3cc27005ecad5a809a83402d37b4f Mon Sep 17 00:00:00 2001 From: TaeHee Lee Date: Wed, 19 Nov 2025 17:51:05 +0900 Subject: [PATCH 1/2] =?UTF-8?q?=EB=AC=B8=EC=A0=9C=20=ED=8F=B4=EB=8D=94=20?= =?UTF-8?q?=EC=97=85=EB=A1=9C=EB=93=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\213\244 \352\264\200\353\246\254\355\225\230\352\270\260.md" | 0 ...5\225\221 \354\247\200\353\242\260\354\260\276\352\270\260.md" | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 "11\354\233\224/3\354\243\274\354\260\250/\353\217\231\354\225\204\353\246\254\354\213\244 \352\264\200\353\246\254\355\225\230\352\270\260/\353\217\231\354\225\204\353\246\254\354\213\244 \352\264\200\353\246\254\355\225\230\352\270\260.md" create mode 100644 "11\354\233\224/3\354\243\274\354\260\250/\355\214\214\355\225\221\355\214\214\355\225\221 \354\247\200\353\242\260\354\260\276\352\270\260/\355\214\214\355\225\221\355\214\214\355\225\221 \354\247\200\353\242\260\354\260\276\352\270\260.md" diff --git "a/11\354\233\224/3\354\243\274\354\260\250/\353\217\231\354\225\204\353\246\254\354\213\244 \352\264\200\353\246\254\355\225\230\352\270\260/\353\217\231\354\225\204\353\246\254\354\213\244 \352\264\200\353\246\254\355\225\230\352\270\260.md" "b/11\354\233\224/3\354\243\274\354\260\250/\353\217\231\354\225\204\353\246\254\354\213\244 \352\264\200\353\246\254\355\225\230\352\270\260/\353\217\231\354\225\204\353\246\254\354\213\244 \352\264\200\353\246\254\355\225\230\352\270\260.md" new file mode 100644 index 0000000..e69de29 diff --git "a/11\354\233\224/3\354\243\274\354\260\250/\355\214\214\355\225\221\355\214\214\355\225\221 \354\247\200\353\242\260\354\260\276\352\270\260/\355\214\214\355\225\221\355\214\214\355\225\221 \354\247\200\353\242\260\354\260\276\352\270\260.md" "b/11\354\233\224/3\354\243\274\354\260\250/\355\214\214\355\225\221\355\214\214\355\225\221 \354\247\200\353\242\260\354\260\276\352\270\260/\355\214\214\355\225\221\355\214\214\355\225\221 \354\247\200\353\242\260\354\260\276\352\270\260.md" new file mode 100644 index 0000000..e69de29 From 6a34e4587aaaccd39fa5424a6ac3f9d40b459edc Mon Sep 17 00:00:00 2001 From: TaeHee Lee Date: Wed, 19 Nov 2025 17:54:34 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[SEA]=20=ED=8C=8C=ED=95=91=ED=8C=8C?= =?UTF-8?q?=ED=95=91=20=EC=A7=80=EB=A2=B0=EC=B0=BE=EA=B8=B0=20/=20=3F=20/?= =?UTF-8?q?=2050=EB=B6=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 처음에 문제를 잘못 이해해서 별의 개수처럼 덩어리만 구하면 될 줄 알았는데, 근처에 지뢰가 없어야만 가능하더군요. 따라서 근처에 지뢰가 있는지부터 확인 후, 없다면 덩어리로 열었습니다. 이후에 덩어리로 열지 못한 칸들을 열어 문제를 해결했습니다. 코드 자체는 bfs코드라서 어렵지 않게 짤 수 있었습니다. --- .../LeeTaeHee.java" | 117 ++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 "11\354\233\224/3\354\243\274\354\260\250/\355\214\214\355\225\221\355\214\214\355\225\221 \354\247\200\353\242\260\354\260\276\352\270\260/LeeTaeHee.java" diff --git "a/11\354\233\224/3\354\243\274\354\260\250/\355\214\214\355\225\221\355\214\214\355\225\221 \354\247\200\353\242\260\354\260\276\352\270\260/LeeTaeHee.java" "b/11\354\233\224/3\354\243\274\354\260\250/\355\214\214\355\225\221\355\214\214\355\225\221 \354\247\200\353\242\260\354\260\276\352\270\260/LeeTaeHee.java" new file mode 100644 index 0000000..d537eb5 --- /dev/null +++ "b/11\354\233\224/3\354\243\274\354\260\250/\355\214\214\355\225\221\355\214\214\355\225\221 \354\247\200\353\242\260\354\260\276\352\270\260/LeeTaeHee.java" @@ -0,0 +1,117 @@ +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.ArrayDeque; +import java.util.Queue; + +public class 파핑파핑지뢰찾기 { + + private static int T; + private static int N; + private static char[][] map; + private static boolean[][] visited; + private static int[][] count; + private static int ans; + + // 8방향 + private static final int[] dx = {1, 1, 1, 0, 0, -1, -1, -1}; + private static final int[] dy = {1, 0, -1, 1, -1, 1, 0, -1}; + + // 지뢰가 없는 칸의 근처에 있는 지뢰 개수 계산 + private static void countMine() { + for (int x = 0; x < N; x++) { + for (int y = 0; y < N; y++) { + + if (map[x][y] == '*') continue; + int cnt = 0; + + for (int i = 0; i < 8; i++) { + int nx = x + dx[i]; + int ny = y + dy[i]; + + if (nx < 0 || nx >= N || ny < 0 || ny >= N) continue; + + if (map[nx][ny] == '*') cnt++; + } + + count[x][y] = cnt; + } + } + } + + // 지뢰가 아닌 덩어리 한번에 열기 + private static void bfs(int x, int y) { + Queue q = new ArrayDeque<>(); + visited[x][y] = true; + q.offer(new int[]{x, y}); + + while (!q.isEmpty()) { + int[] cur = q.poll(); + int cx = cur[0]; + int cy = cur[1]; + + if (count[cx][cy] == 0) { + for (int i = 0; i < 8; i++) { + int nx = cx + dx[i]; + int ny = cy + dy[i]; + + if (nx < 0 || nx >= N || ny < 0 || ny >= N) continue; + if (visited[nx][ny] || map[nx][ny] == '*') continue; + + visited[nx][ny] = true; + q.offer(new int[]{nx, ny}); + } + } + } + } + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringBuilder sb = new StringBuilder(); + + T = Integer.parseInt(br.readLine()); + + for (int tc = 1; tc <= T; tc++) { + N = Integer.parseInt(br.readLine()); + + map = new char[N][N]; + visited = new boolean[N][N]; + count = new int[N][N]; + + for (int i = 0; i < N; i++) { + String line = br.readLine(); + for (int j = 0; j < N; j++) { + map[i][j] = line.charAt(j); + } + } + + // 각 칸별로 근처에 지뢰가 몇개 있는지 계싼 + countMine(); + + ans = 0; + + // 근처에 지뢰가 없다면 덩어리 계산하여 열기 + for (int x = 0; x < N; x++) { + for (int y = 0; y < N; y++) { + if (map[x][y] == '.' && !visited[x][y] && count[x][y] == 0) { + bfs(x, y); + ans++; + } + } + } + + // 아직 남아있는 지뢰 없는 칸 확인 + for (int x = 0; x < N; x++) { + for (int y = 0; y < N; y++) { + if (map[x][y] == '.' && !visited[x][y]) { + ans++; + visited[x][y] = true; + } + } + } + + sb.append("#" + tc + " " + ans + "\n"); + } + + System.out.print(sb); + } +}