From 6b5b8772595db413cd89bd4e0c6c8f023de7d52d Mon Sep 17 00:00:00 2001 From: Jonghwan Lee <123362165+0224LJH@users.noreply.github.com> Date: Mon, 21 Jul 2025 23:38:34 +0900 Subject: [PATCH] =?UTF-8?q?[20250721]=20BOJ=20/=20G3=20/=20=EC=86=8C?= =?UTF-8?q?=EB=AC=B8=EB=82=9C=20=EC=B9=A0=EA=B3=B5=EC=A3=BC=20/=20?= =?UTF-8?q?=EC=9D=B4=EC=A2=85=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ... \354\271\240\352\263\265\354\243\274 .md" | 107 ++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 "0224LJH/202507/21 BOJ \354\206\214\353\254\270\353\202\234 \354\271\240\352\263\265\354\243\274 .md" diff --git "a/0224LJH/202507/21 BOJ \354\206\214\353\254\270\353\202\234 \354\271\240\352\263\265\354\243\274 .md" "b/0224LJH/202507/21 BOJ \354\206\214\353\254\270\353\202\234 \354\271\240\352\263\265\354\243\274 .md" new file mode 100644 index 00000000..e8bcaed5 --- /dev/null +++ "b/0224LJH/202507/21 BOJ \354\206\214\353\254\270\353\202\234 \354\271\240\352\263\265\354\243\274 .md" @@ -0,0 +1,107 @@ +```java +import java.awt.*; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.HashSet; +import java.util.Set; + + +public class Main { + static String[][] arr = new String[5][5]; + static Set set = new HashSet<>(); + static HashSet temp = new HashSet<>(); + static int[] dy = { -1,0,1,0}; + static int[] dx = { 0,1,0,-1}; + static int ans = 0; + + + public static void main(String[] args) throws IOException { + init(); + process(); + print(); + } + + private static void init() throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + for (int i = 0; i < 5; i++) { + arr[i] = br.readLine().split(""); + } + } + + private static void process() throws IOException { + combination(0,0); + } + + private static void combination(int num, int idx) { + if ( idx == 7) { + check(); + return; + } + + for (int i = num; i < 25; i++){ + int y = i/5; + int x = i%5; + + set.add(new Point(x, y)); + combination(i+1, idx+1); + set.remove(new Point(x, y)); + } + } + + private static void check() { + + + Point first = set.iterator().next(); + + int sCount = 0; + for (Point p : set) { + if(arr[p.y][p.x].equals("S") ) sCount++; + } + + + if (sCount >= 4 && checkConnected(first)) { + ans++; + } + + } + + private static boolean checkConnected(Point first) { + temp = new HashSet<>(); + temp.add(first); + + for (int i = 0 ; i < 7; i++){ + for (Point p : set) { + if (temp.contains(p)) continue; + + boolean isConnected = false; + for (int j = 0; j <4 ; j++){ + int ny = p.y + dy[j]; + int nx = p.x + dx[j]; + + if (temp.contains(new Point(nx, ny))) { + isConnected = true; + break; + } + } + + if (isConnected) { + temp.add(p); + } + } + } + + return temp.size() == 7; + + } + + + private static void print() { + System.out.println(ans); + } + + + +} + +``` \ No newline at end of file