From 49f1f73aba02732aae6b404f307092a0f451b2f1 Mon Sep 17 00:00:00 2001 From: Sohyun Eom <88651937+sohy19@users.noreply.github.com> Date: Thu, 5 Oct 2023 20:45:53 +0900 Subject: [PATCH 01/11] [solved] boj2660.java --- EomSoHyun/BOJ/boj2660.java | 83 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 EomSoHyun/BOJ/boj2660.java diff --git a/EomSoHyun/BOJ/boj2660.java b/EomSoHyun/BOJ/boj2660.java new file mode 100644 index 00000000..467c8624 --- /dev/null +++ b/EomSoHyun/BOJ/boj2660.java @@ -0,0 +1,83 @@ +import java.io.*; +import java.util.*; + +public class Main { + + static int n, minScore, minCnt; + static List result; + static List[] candi; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + StringBuilder sb = new StringBuilder(); + + n = Integer.parseInt(st.nextToken()); // 회원의 수 + candi = new ArrayList[n]; + + for (int i = 0; i < n; i++) { + candi[i] = new ArrayList<>(); + } + + while (true) { + st = new StringTokenizer(br.readLine()); + int v1 = Integer.parseInt(st.nextToken()); + int v2 = Integer.parseInt(st.nextToken()); + + if (v1 == -1) break; + + candi[v1-1].add(v2-1); + candi[v2-1].add(v1-1); + } + + minScore = Integer.MAX_VALUE; + minCnt = Integer.MAX_VALUE; + result = new ArrayList<>(); + + for (int i = 0; i < n; i++) { + int score = bfs(i); + if (score < minScore) { + minCnt = 1; + minScore = score; + result.clear(); + result.add(i+1); + } + else if (score == minScore) { + minCnt++; + result.add(i+1); + } + } + + sb.append(minScore).append(" ").append(minCnt).append("\n"); + for (int i = 0; i < result.size(); i++) { + sb.append(result.get(i)).append(" "); + } + + System.out.println(sb); + + } + + public static int bfs(int x) { + boolean[] visited = new boolean[n]; + visited[x] = true; + Queue q = new LinkedList<>(); + q.offer(new int[] {x, 0}); + int minCnt = 0; + + while (!q.isEmpty()) { + int v[] = q.poll(); + for (Integer w: candi[v[0]]) { + if (visited[w]) continue; + visited[w] = true; + q.offer(new int[] {w, v[1] + 1}); + if (minCnt < v[1] + 1) { + minCnt = v[1] + 1; + } + } + } + + return minCnt; + + + } +} From 56aa7c8fb6582d87b0befa27ff4ea514be918339 Mon Sep 17 00:00:00 2001 From: Sohyun Eom <88651937+sohy19@users.noreply.github.com> Date: Wed, 11 Oct 2023 13:39:36 +0900 Subject: [PATCH 02/11] [solved] boj2792.java --- EomSoHyun/BOJ/boj2792.java | 49 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 EomSoHyun/BOJ/boj2792.java diff --git a/EomSoHyun/BOJ/boj2792.java b/EomSoHyun/BOJ/boj2792.java new file mode 100644 index 00000000..5ee5dd59 --- /dev/null +++ b/EomSoHyun/BOJ/boj2792.java @@ -0,0 +1,49 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +public class Main { + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + int n = Integer.parseInt(st.nextToken()); // 아이들 수 + int m = Integer.parseInt(st.nextToken()); // 색상 수 + + int start = 1; + int end = 0; + + int nums[] = new int[m]; // 각 색상의 보석 수 + for (int i = 0; i < nums.length; i++) { + nums[i] = Integer.parseInt(br.readLine()); + if (end < nums[i]) { + end = nums[i]; + } + } + + int rst = Integer.MAX_VALUE; + while (start <= end) { + int mid = (start + end) / 2; + + int cnt = 0; + for (int i = 0; i < nums.length; i++) { + cnt += nums[i] % mid == 0 ? nums[i] / mid : nums[i] / mid + 1; + } + + if (cnt <= n) { + end = mid - 1; + rst = Integer.min(rst, mid); + } + + else { + start = mid + 1; + } + + } + + System.out.println(rst); + } + +} From bd3d210cc35d984b4df5ba789e7f1a0c764ae10a Mon Sep 17 00:00:00 2001 From: Sohyun Eom <88651937+sohy19@users.noreply.github.com> Date: Wed, 11 Oct 2023 17:17:04 +0900 Subject: [PATCH 03/11] [solved] boj16234.java --- EomSoHyun/BOJ/boj16234.java | 87 +++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 EomSoHyun/BOJ/boj16234.java diff --git a/EomSoHyun/BOJ/boj16234.java b/EomSoHyun/BOJ/boj16234.java new file mode 100644 index 00000000..f9704d03 --- /dev/null +++ b/EomSoHyun/BOJ/boj16234.java @@ -0,0 +1,87 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.LinkedList; +import java.util.Queue; +import java.util.StringTokenizer; + +public class Main { + + static int N, L, R, sum, cnt; + static int[][] A; + static boolean[][] visited; + static Queue pos; + static int[] dx = {0, 0, 1, -1}; + static int[] dy = {1, -1, 0, 0}; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + N = Integer.parseInt(st.nextToken()); // 땅 크기 + L = Integer.parseInt(st.nextToken()); // L명 이상 + R = Integer.parseInt(st.nextToken()); // R명 이하 + + A = new int[N][N]; // 각 나라 인구 수 + + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < N; j++) { + A[i][j] = Integer.parseInt(st.nextToken()); + } + } + + + int rst = 0; + pos = new LinkedList(); + while (true) { + boolean flag = true; + visited = new boolean[N][N]; // 방문 표시 + for (int i = 0; i < N; i++) { + for (int j = 0; j < N; j++) { + if (!visited[i][j]) { + sum = 0; + cnt = 0; + dfs(i, j); + if (cnt > 1) { + flag = false; + while (!pos.isEmpty()) { + int[] xy = pos.poll(); + A[xy[0]][xy[1]] = sum / cnt; + } + } else { + visited[i][j] = false; + pos.clear(); + } + } + } + } + + if (flag) break; + rst++; + } + + System.out.println(rst); + + } + + public static void dfs(int x, int y) { + pos.offer(new int[] {x, y}); + visited[x][y] = true; + sum += A[x][y]; + cnt++; + + for (int i = 0; i < 4; i++) { + int nx = x + dx[i]; + int ny = y + dy[i]; + if (0 <= nx && nx < N && 0 <= ny && ny < N) { + if (L <= Math.abs(A[x][y] - A[nx][ny]) && Math.abs(A[x][y] - A[nx][ny]) <= R && !visited[nx][ny]) { + dfs(nx, ny); + } + } + + } + } + +} From c5cf7a8be0641280f02f8a3561e68f7af0a5f8aa Mon Sep 17 00:00:00 2001 From: Sohyun Eom <88651937+sohy19@users.noreply.github.com> Date: Thu, 12 Oct 2023 13:56:51 +0900 Subject: [PATCH 04/11] [solved] boj16719.java --- EomSoHyun/BOJ/boj.ZOAC.java | 52 +++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 EomSoHyun/BOJ/boj.ZOAC.java diff --git a/EomSoHyun/BOJ/boj.ZOAC.java b/EomSoHyun/BOJ/boj.ZOAC.java new file mode 100644 index 00000000..57e2b3db --- /dev/null +++ b/EomSoHyun/BOJ/boj.ZOAC.java @@ -0,0 +1,52 @@ +import java.io.*; +import java.util.*; + +public class Main { + + static String str; + static boolean[] mark; + static StringBuilder sb; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + sb = new StringBuilder(); + + str = br.readLine(); + mark = new boolean[str.length()]; + + ZOAC(0, str.length()-1); + + System.out.println(sb); + + + } + + public static void ZOAC(int start, int end) { + if (start > end) { + return; + } + + int idx = start; + for (int i = start+1; i <= end; i++) { + if (str.charAt(idx) > str.charAt(i)) { + idx = i; + } + } + mark[idx] = true; + print(); + ZOAC(idx+1, end); + ZOAC(start, idx-1); + + + } + + public static void print() { + for (int i = 0; i < str.length(); i++) { + if (mark[i]) { + sb.append(str.charAt(i)); + } + } + sb.append('\n'); + } + +} From 4ca2f25783733ef317538e497185c8e51f9a3168 Mon Sep 17 00:00:00 2001 From: Sohyun Eom <88651937+sohy19@users.noreply.github.com> Date: Thu, 12 Oct 2023 13:57:24 +0900 Subject: [PATCH 05/11] [solved] boj16719.java --- EomSoHyun/BOJ/{boj.ZOAC.java => boj16719.java} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename EomSoHyun/BOJ/{boj.ZOAC.java => boj16719.java} (100%) diff --git a/EomSoHyun/BOJ/boj.ZOAC.java b/EomSoHyun/BOJ/boj16719.java similarity index 100% rename from EomSoHyun/BOJ/boj.ZOAC.java rename to EomSoHyun/BOJ/boj16719.java From 4c42363dbc36e181b282e14c0f1deafbb4167f74 Mon Sep 17 00:00:00 2001 From: Sohyun Eom <88651937+sohy19@users.noreply.github.com> Date: Mon, 16 Oct 2023 23:16:20 +0900 Subject: [PATCH 06/11] [solved] boj16197.java --- EomSoHyun/BOJ/boj16197.java | 95 +++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 EomSoHyun/BOJ/boj16197.java diff --git a/EomSoHyun/BOJ/boj16197.java b/EomSoHyun/BOJ/boj16197.java new file mode 100644 index 00000000..78ea1e23 --- /dev/null +++ b/EomSoHyun/BOJ/boj16197.java @@ -0,0 +1,95 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.LinkedList; +import java.util.Queue; +import java.util.StringTokenizer; + +public class Main { + + static int n, m; + static char[][] map; + static Queue q; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + n = Integer.parseInt(st.nextToken()); + m = Integer.parseInt(st.nextToken()); + map = new char[n][m]; + q = new LinkedList(); + int[] coin = new int[5]; + + int idx = 0; + for (int i = 0; i < n; i++) { + String line = br.readLine(); + for (int j = 0; j < line.length(); j++) { + map[i][j] = line.charAt(j); + if (map[i][j] == 'o') { + coin[idx++] = i; + coin[idx++] = j; + } + } + } + coin[4] = 0; + q.offer(coin); + System.out.println(bfs()); + + + + } + + public static int bfs() { + int[] dx = {0, 0, 1, -1}; + int[] dy = {1, -1, 0, 0}; + + + while (true) { + int[] xy = q.poll(); + int cnt = xy[4]; + int[] coin1 = new int[] {xy[0], xy[1]}; + int[] coin2 = new int[] {xy[2], xy[3]}; + + if (cnt++ == 10) break; + + for (int i = 0; i < 4; i++) { + int x1 = coin1[0] + dx[i]; + int x2 = coin2[0] + dx[i]; + int y1 = coin1[1] + dy[i]; + int y2 = coin2[1] + dy[i]; + + if (!(0 <= x1 && x1 < n && 0 <= y1 && y1 < m)) { + if (!(0 <= x2 && x2 < n && 0 <= y2 && y2 < m)) { + // 둘 다 떨어짐 + continue; + } + else { + // coin1 떨어짐 + return cnt; + } + } + else if (!(0 <= x2 && x2 < n && 0 <= y2 && y2 < m)) { + // coin2 떨어짐 + return cnt; + } + else { + if (map[x1][y1] == '#') { + x1 = coin1[0]; + y1 = coin1[1]; + } + if (map[x2][y2] == '#') { + x2 = coin2[0]; + y2 = coin2[1]; + } + q.offer(new int[] {x1, y1, x2, y2, cnt}); + } + + } + } + + return -1; + + } + +} From c94c63d51cde4b60ac45eeded759cff1e2b8d1ee Mon Sep 17 00:00:00 2001 From: Sohyun Eom <88651937+sohy19@users.noreply.github.com> Date: Tue, 17 Oct 2023 15:20:12 +0900 Subject: [PATCH 07/11] [solved] boj4811.java --- EomSoHyun/BOJ/boj4811.java | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 EomSoHyun/BOJ/boj4811.java diff --git a/EomSoHyun/BOJ/boj4811.java b/EomSoHyun/BOJ/boj4811.java new file mode 100644 index 00000000..eac2e2cd --- /dev/null +++ b/EomSoHyun/BOJ/boj4811.java @@ -0,0 +1,37 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class Main { + + static int cnt, n; + static long[] nums; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringBuilder sb = new StringBuilder(); + + while (true) { + n = Integer.parseInt(br.readLine()); + if (n == 0) break; + nums = new long[n+1]; + nums[0] = 1; + nums[1] = 1; + + for (int i = 2; i < nums.length; i++) { + for (int j = 0; j < i; j++) { + nums[i] += nums[j] * nums[i-j-1]; + } + } + sb.append(nums[n]).append('\n'); + + } + + System.out.println(sb); + + } + + +} + + From e509d2a35b7088e7e4dba96d481fd2bae012656a Mon Sep 17 00:00:00 2001 From: Sohyun Eom <88651937+sohy19@users.noreply.github.com> Date: Wed, 18 Oct 2023 19:51:05 +0900 Subject: [PATCH 08/11] [solved] boj15989.java --- EomSoHyun/BOJ/boj15989.java | 42 +++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 EomSoHyun/BOJ/boj15989.java diff --git a/EomSoHyun/BOJ/boj15989.java b/EomSoHyun/BOJ/boj15989.java new file mode 100644 index 00000000..23df53a4 --- /dev/null +++ b/EomSoHyun/BOJ/boj15989.java @@ -0,0 +1,42 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class Main { + + static int[][] dp; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringBuilder sb = new StringBuilder(); + + int T = Integer.parseInt(br.readLine()); + + for (int t = 1; t <= T; t++) { + int n = Integer.parseInt(br.readLine()); + dp = new int[4][n+1]; + + for (int i = 0; i < 4; i++) { + dp[i][0] = 1; + } + for (int i = 0; i < n+1; i++) { + dp[1][i] = 1; + } + + for (int i = 2; i <= 3; i++) { + for (int j = 1; j <= n; j++) { + dp[i][j] = dp[i-1][j]; // i 선택 X + if (j-i >= 0) { + dp[i][j] += dp[i][j-i]; + } + } + } + + sb.append(dp[3][n]).append('\n'); + } + + System.out.println(sb); + + } + +} From 3af4c601fe3a87db69011fa8b68ef0faf4577e13 Mon Sep 17 00:00:00 2001 From: Sohyun Eom <88651937+sohy19@users.noreply.github.com> Date: Thu, 19 Oct 2023 19:26:39 +0900 Subject: [PATCH 09/11] [solved] boj17297.java --- EomSoHyun/BOJ/boj17297.java | 78 +++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 EomSoHyun/BOJ/boj17297.java diff --git a/EomSoHyun/BOJ/boj17297.java b/EomSoHyun/BOJ/boj17297.java new file mode 100644 index 00000000..61becd18 --- /dev/null +++ b/EomSoHyun/BOJ/boj17297.java @@ -0,0 +1,78 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; + +public class Main { + + static int m; + static List nums; + static String str1 = "Messi"; + static String str2 = "Messi Gimossi"; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + m = Integer.parseInt(br.readLine()); + + nums = new ArrayList<>(); + nums.add(0); + nums.add(5); + nums.add(13); + + int i = 0; + if (m > 13) { + i = 3; + while (true) { + nums.add(nums.get(i - 1) + nums.get(i - 2) + 1); + if (nums.get(i) >= m) break; + i++; + } + + } + + if (m <= 5) { + i = 1; + } + else if (m <= 13) { + i = 2; + } + + Messi(m, i); + + } + + public static void Messi(int m, int i) { + if (i == 1) { + System.out.println(str1.charAt(m-1)); + return; + } + + else if (i == 2) { + char ch = str2.charAt(m-1); + if (ch == ' ') { + System.out.println("Messi Messi Gimossi"); + } + else { + System.out.println(ch); + } + return; + } + + if (m == nums.get(i-1) + 1) { + System.out.println("Messi Messi Gimossi"); + return; + } + + if (m > nums.get(i-1)) { + m = m - (nums.get(i-1) + 1); + Messi(m, i-2); + } + + else { + Messi(m, i-1); + } + } + +} From dfe89f8d2e519c427c993dd4bf6c5c9c691c5f2b Mon Sep 17 00:00:00 2001 From: Sohyun Eom <88651937+sohy19@users.noreply.github.com> Date: Thu, 19 Oct 2023 19:39:40 +0900 Subject: [PATCH 10/11] [solved] boj17297.java --- EomSoHyun/BOJ/boj17297.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/EomSoHyun/BOJ/boj17297.java b/EomSoHyun/BOJ/boj17297.java index 61becd18..46da75b4 100644 --- a/EomSoHyun/BOJ/boj17297.java +++ b/EomSoHyun/BOJ/boj17297.java @@ -8,8 +8,7 @@ public class Main { static int m; static List nums; - static String str1 = "Messi"; - static String str2 = "Messi Gimossi"; + static String str = "Messi Gimossi"; public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); @@ -45,12 +44,12 @@ else if (m <= 13) { public static void Messi(int m, int i) { if (i == 1) { - System.out.println(str1.charAt(m-1)); + System.out.println(str.charAt(m-1)); return; } else if (i == 2) { - char ch = str2.charAt(m-1); + char ch = str.charAt(m-1); if (ch == ' ') { System.out.println("Messi Messi Gimossi"); } From cf410614d5064a1440047e13cfdbe6cede3f5e78 Mon Sep 17 00:00:00 2001 From: Sohyun Eom <88651937+sohy19@users.noreply.github.com> Date: Thu, 19 Oct 2023 21:01:24 +0900 Subject: [PATCH 11/11] [solved] boj2661.java --- EomSoHyun/BOJ/boj2661.java | 53 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 EomSoHyun/BOJ/boj2661.java diff --git a/EomSoHyun/BOJ/boj2661.java b/EomSoHyun/BOJ/boj2661.java new file mode 100644 index 00000000..8d92ce79 --- /dev/null +++ b/EomSoHyun/BOJ/boj2661.java @@ -0,0 +1,53 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class Main { + + static int n; + static int[] nums; + static boolean flag; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + n = Integer.parseInt(br.readLine()); + nums = new int[n]; + nums[0] = 1; + makeGoodNums(1); + } + + public static boolean check(int idx) { + for (int i = 1; i <= idx/2; i++) { + boolean flag = false; + for (int j = 0; j < i; j++) { + if (nums[idx-i-j-1] != nums[idx-j-1]) { + flag = true; + } + } + if (!flag) return false; + } + return true; + } + + public static void makeGoodNums(int idx) { + if (flag) { + return; + } + + if (idx == n) { + for (int i = 0; i < n; i++) { + System.out.print(nums[i]); + } + flag = true; + return; + } + + for (int i = 1; i < 4; i++) { + nums[idx] = i; + if (check(idx + 1)) { + makeGoodNums(idx+1); + } + } + } +}