From a35540ccf005120aa389eb7ed806b42ec5b5669d Mon Sep 17 00:00:00 2001 From: dk7648 Date: Thu, 22 Aug 2024 20:02:41 +0900 Subject: [PATCH 1/5] =?UTF-8?q?complete=20[W7]=20=EB=AC=B8=EC=9E=90?= =?UTF-8?q?=EC=97=B4=20=ED=8F=AD=EB=B0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "7\354\243\274\354\260\250/KBC/boj_9935.java" | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 "7\354\243\274\354\260\250/KBC/boj_9935.java" diff --git "a/7\354\243\274\354\260\250/KBC/boj_9935.java" "b/7\354\243\274\354\260\250/KBC/boj_9935.java" new file mode 100644 index 0000000..1859fbc --- /dev/null +++ "b/7\354\243\274\354\260\250/KBC/boj_9935.java" @@ -0,0 +1,43 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Stack; + +//BOJ 9935 [문자열 폭발] +public class Main { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringBuilder sb = new StringBuilder(); + + Stack stack = new Stack<>(); + String sentence = br.readLine(); + String bomb = br.readLine(); + + for (char ch : sentence.toCharArray()) { + stack.add(ch); + if (stack.size() >= bomb.length()) { + boolean isBombed = true; + for (int i = 0; i < bomb.length(); i++) { + if (stack.get((stack.size() - bomb.length()) + i) != bomb.charAt(i)) { + isBombed = false; + break; + } + } + if (isBombed) { + for (int i = 0; i < bomb.length(); i++) { + stack.pop(); + } + } + } + } + + if (stack.isEmpty()) { + System.out.println("FRULA"); + } else { + for(char ch : stack) { + sb.append(ch); + } + System.out.println(sb); + } + } +} From 21195e95d94b3313c05bf989722c9a8d59bd8672 Mon Sep 17 00:00:00 2001 From: dk7648 Date: Thu, 22 Aug 2024 20:02:55 +0900 Subject: [PATCH 2/5] =?UTF-8?q?complete=20[W8]=20=EC=B9=98=ED=82=A8=20?= =?UTF-8?q?=EB=B0=B0=EB=8B=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../KBC/boj_15686.java" | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 "7\354\243\274\354\260\250/KBC/boj_15686.java" diff --git "a/7\354\243\274\354\260\250/KBC/boj_15686.java" "b/7\354\243\274\354\260\250/KBC/boj_15686.java" new file mode 100644 index 0000000..3401652 --- /dev/null +++ "b/7\354\243\274\354\260\250/KBC/boj_15686.java" @@ -0,0 +1,91 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; + +//BOJ 15686 [치킨 배달] +public class Main { + static int N; + static int M; + static List houses; + static List stores; + static int numberOfStore; + static boolean[] isVisited; + static int[] selectedStore; + static int result; + + + public static class Pos { + int x; + int y; + + public Pos(int x, int y) { + this.x = x; + this.y = y; + } + + public int getDistance(Pos p) { + return Math.abs(x - p.x) + Math.abs(y - p.y); + } + } + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + initialize(br); + dfs(0, 0); + System.out.println(result); + } + + public static void initialize(BufferedReader br) throws IOException { + String[] input = br.readLine().split(" "); + N = Integer.parseInt(input[0]); + M = Integer.parseInt(input[1]); + houses = new ArrayList<>(); + stores = new ArrayList<>(); + + for (int y = 1; y <= N; y++) { + String[] line = br.readLine().split(" "); + for (int x = 1; x <= N; x++) { + if (line[x - 1].equals("1")) { + houses.add(new Pos(x, y)); + } + if (line[x - 1].equals("2")) { + stores.add(new Pos(x, y)); + } + } + } + + numberOfStore = stores.size(); + isVisited = new boolean[numberOfStore]; + selectedStore = new int[M]; + result = Integer.MAX_VALUE; + } + + public static void dfs(int depth, int init) { + if (depth == M) { + //도시의 치킨 거리 구하기 + result = Math.min(result, getTotalDistance()); + return; + } + //치킨집 M개 선택 + for (int i = init; i < stores.size(); i++) { + selectedStore[depth] = i; + dfs(depth + 1, i + 1); + } + } + + public static int getTotalDistance() { + int totalDistance = 0; + for (Pos house : houses) { + int distance = Integer.MAX_VALUE; + for (int depth = 0; depth < M; depth++) { + int index = selectedStore[depth]; + Pos store = stores.get(index); + distance = Math.min(distance, house.getDistance(store)); + } + totalDistance += distance; + } + return totalDistance; + } +} \ No newline at end of file From db7f7d79587867148b1ac748a5a584f6216b77e1 Mon Sep 17 00:00:00 2001 From: dk7648 Date: Thu, 22 Aug 2024 20:03:29 +0900 Subject: [PATCH 3/5] =?UTF-8?q?complete=20[W7]=20=EC=A7=91=ED=95=A9?= =?UTF-8?q?=EC=9D=98=20=ED=91=9C=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "7\354\243\274\354\260\250/KBC/boj_1717.java" | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 "7\354\243\274\354\260\250/KBC/boj_1717.java" diff --git "a/7\354\243\274\354\260\250/KBC/boj_1717.java" "b/7\354\243\274\354\260\250/KBC/boj_1717.java" new file mode 100644 index 0000000..6fd3b81 --- /dev/null +++ "b/7\354\243\274\354\260\250/KBC/boj_1717.java" @@ -0,0 +1,64 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.*; + + +//BOJ 1717 집합의 표현 +public class Main { + static int[] pointer; + static int[] priority; + static final int UNION = 0; + static final int COMPARE = 1; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + String[] input = br.readLine().split(" "); + int n = Integer.parseInt(input[0]); + int m = Integer.parseInt(input[1]); + + pointer = new int[n + 1]; + priority = new int[n + 1]; + for (int i = 0; i <= n; i++) { + pointer[i] = i; + } + + for (int i = 0; i < m; i++) { + int[] temp = Arrays.stream(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); + int type = temp[0]; + int lSet = find(temp[1]); + int rSet = find(temp[2]); + + if (type == UNION) { + if(lSet == rSet) continue; + if (priority[lSet] > priority[rSet]) { + pointer[rSet] = lSet; + } else { + pointer[lSet] = rSet; + if(priority[lSet] == priority[rSet]) + priority[rSet]++; + } + } + if (type == COMPARE) { + if (lSet == rSet) { + System.out.println("YES"); + } else { + System.out.println("NO"); + } + } + } + } + + public static int find(int x) { + if (pointer[x] == x) { + return x; + } else { + return find(pointer[x]); + } + } +} +//1 2 +//0 0 1 +//1 0 1 +// +// \ No newline at end of file From a3b600e5332674c832e1313ab1b60481a4c9e0ee Mon Sep 17 00:00:00 2001 From: dk7648 Date: Thu, 22 Aug 2024 20:03:59 +0900 Subject: [PATCH 4/5] =?UTF-8?q?complete=20[W7]=20=EB=B0=95=EC=8A=A4=20?= =?UTF-8?q?=EB=82=98=EB=88=84=EA=B8=B0=20=EA=B2=8C=EC=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../KBC/boj_11867.java" | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 "7\354\243\274\354\260\250/KBC/boj_11867.java" diff --git "a/7\354\243\274\354\260\250/KBC/boj_11867.java" "b/7\354\243\274\354\260\250/KBC/boj_11867.java" new file mode 100644 index 0000000..d6d1965 --- /dev/null +++ "b/7\354\243\274\354\260\250/KBC/boj_11867.java" @@ -0,0 +1,29 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +//BOJ 11867 박스 나누기 게임 +public class Main { + static final boolean WIN = true; + static final boolean LOSE = false; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + String[] input = br.readLine().split(" "); + int n = Integer.parseInt(input[0]); + int m = Integer.parseInt(input[1]); + int max = Math.max(n, m); + boolean[] dp = new boolean[max + 1]; + dp[1] = LOSE; + dp[2] = WIN; + + for (int i = 3; i <= max; i++) { + for (int k = 1; k <= i / 2; k++) { + dp[i] = !(dp[k] | dp[i - k]); + if(dp[i]) break; + } + } + + System.out.println(dp[n] | dp[m] ? "A" : "B"); + } +} \ No newline at end of file From 6281100253eb930c6393de70f31a346dd3529b33 Mon Sep 17 00:00:00 2001 From: dk7648 Date: Thu, 22 Aug 2024 20:04:55 +0900 Subject: [PATCH 5/5] =?UTF-8?q?imcomplete=20[W7]=20=EC=A4=91=EB=9F=89?= =?UTF-8?q?=EC=A0=9C=ED=95=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "7\354\243\274\354\260\250/KBC/boj_1939.java" | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 "7\354\243\274\354\260\250/KBC/boj_1939.java" diff --git "a/7\354\243\274\354\260\250/KBC/boj_1939.java" "b/7\354\243\274\354\260\250/KBC/boj_1939.java" new file mode 100644 index 0000000..2f3f5d0 --- /dev/null +++ "b/7\354\243\274\354\260\250/KBC/boj_1939.java" @@ -0,0 +1,83 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import static java.lang.Math.max; +import static java.lang.Math.min; + +//BOJ 1939 중량제한 +public class Main { + static boolean[] isVisit; + static int[] prevWeight; + static List> paths; + static int maxWeight; + + public static class Island { + + int number; + int weight; + + public Island(int target, int weight) { + this.number = target; + this.weight = weight; + } + } + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + //초기 데이터 n, m + int[] set = Arrays.stream(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); + //이전까지 도달했던 최대중량 값 + prevWeight = new int[set[0] + 1]; + //최대 중량 + maxWeight = 0; + isVisit = new boolean[set[0] + 1]; + + //다음 섬의 이름과 중량에 대한 정보를 담은 Graph클래스 + //Graph클래스를 2차원배열로 선언, 각 섬마다 갈 수 있는 다음 섬을 담을 것 + paths = new ArrayList<>(); + for (int i = 0; i <= set[0]; i++) { + paths.add(new ArrayList<>()); + } + + + for (int i = 0; i < set[1]; i++) { + int[] input = Arrays.stream(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); + int source = input[0]; + int target = input[1]; + int weight = input[2]; + + //양방향 그래프 + paths.get(source).add(new Island(target, weight)); + paths.get(target).add(new Island(source, weight)); + } + + //최대중량을 구하고자 하는 경로 + int[] path = Arrays.stream(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); + int source = path[0]; + int target = path[1]; + + dfs(source, target, Integer.MAX_VALUE); + System.out.println(maxWeight); + } + + //현재 위치, 목표 위치, 지금 까지 거친 경로에서 가능한 최대중량 + public static void dfs(int source, int target, int weight) { + if (source == target) { + maxWeight = max(maxWeight, weight); + return; + } + + if (!isVisit[source] && weight > prevWeight[source]) { + isVisit[source] = true; + prevWeight[source] = weight; + for (Island island : paths.get(source)) { + dfs(island.number, target, min(weight, island.weight)); + } + isVisit[source] = false; + } + } +} \ No newline at end of file