From 77f61f06c69b28e46e5acf3b0871391900d9ba61 Mon Sep 17 00:00:00 2001 From: Jimin Date: 2025年3月25日 10:53:23 +0900 Subject: [PATCH 1/4] =?UTF-8?q?=EC=86=90=EC=A7=80=EB=AF=BC=20[CT]=20?= =?UTF-8?q?=EB=82=98=EB=AC=B4=20=EB=B0=95=EB=A9=B8=5F250325?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...353円254円264円353円260円225円353円251円270円.java" | 163 ++++++++++++++++++ 1 file changed, 163 insertions(+) create mode 100644 "CodeTree/2021-2022353円205円204円/JM_353円202円230円353円254円264円353円260円225円353円251円270円.java" diff --git "a/CodeTree/2021-2022353円205円204円/JM_353円202円230円353円254円264円353円260円225円353円251円270円.java" "b/CodeTree/2021-2022353円205円204円/JM_353円202円230円353円254円264円353円260円225円353円251円270円.java" new file mode 100644 index 00000000..ceb6e33b --- /dev/null +++ "b/CodeTree/2021-2022353円205円204円/JM_353円202円230円353円254円264円353円260円225円353円251円270円.java" @@ -0,0 +1,163 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +public class JM_나무박멸 { + static int N; + static int M; // 박멸이 진행되는 년 수 + static int K; // 제초제의 확산 범위 K + static int C; // 제초제가 남아있는 년 수 C + static int[][] map; // 0(빈칸), -1(벽) + static final int[][] DIR = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}, {-1, -1}, {-1, 1}, {1, -1}, {1, 1}}; + static int[][] herbicide; + + private static boolean inRange(int y, int x) { + return 0 <= y && y < N && 0 <= x && x < N; + } + + private static void reduceHerbicide() { + for (int i = 0; i < N; i++) { + for (int j = 0; j < N; j++) { + if(herbicide[i][j] <= 0) continue; + herbicide[i][j] -= 1; + } + } + } + + private static int[] findMaxRemovedTreePos() { + int[] pos = new int[3]; + for (int i = 0; i < N; i++) { + for (int j = 0; j < N; j++) { + if(map[i][j] <= 0) continue; + + int removedTree = map[i][j]; + for (int d = 4; d < 8; d++) { + int ny = i; + int nx = j; + int k = 0; + while (k++ < K) { + ny += DIR[d][0]; + nx += DIR[d][1]; + if(!inRange(ny, nx) || map[ny][nx] == 0 || map[ny][nx] == -1) break; + removedTree += map[ny][nx]; + } + } + + if(removedTree> pos[2]) { + pos[0] = i; + pos[1] = j; + pos[2] = removedTree; + } + } + } + return pos; + } + + private static int sprayHerbicide() { + int[] pos = findMaxRemovedTreePos(); + int y = pos[0]; + int x = pos[1]; + int removedTree = pos[2]; + + map[y][x] = 0; + herbicide[y][x] = C + 1; + for (int d = 4; d < 8; d++) { + int ny = y; + int nx = x; + int k = 0; + while (k++ < K) { + ny += DIR[d][0]; + nx += DIR[d][1]; + if(!inRange(ny, nx)) break; + herbicide[ny][nx] = C + 1; + if(map[ny][nx] <= 0) break; + map[ny][nx] = 0; + } + } + + return removedTree; + } + + private static int countReproduction(int y, int x) { + int cnt = 0; + for (int k = 0; k < 4; k++) { + int ny = y + DIR[k][0]; + int nx = x + DIR[k][1]; + if(!inRange(ny, nx) || map[ny][nx] != 0 || herbicide[ny][nx]> 0) continue; + cnt++; + } + return cnt == 0 ? 0 : map[y][x] / cnt; + } + + private static void reproduce() { + int[][] tmp = new int[N][N]; + for (int i = 0; i < N; i++) { + for (int j = 0; j < N; j++) { + tmp[i][j] = map[i][j]; + } + } + + for (int i = 0; i < N; i++) { + for (int j = 0; j < N; j++) { + if(map[i][j] <= 0) continue; + + int reproduction = countReproduction(i, j); + if(reproduction == 0) continue; + for (int d = 0; d < 4; d++) { + int ny = i + DIR[d][0]; + int nx = j + DIR[d][1]; + if(!inRange(ny, nx) || map[ny][nx] != 0 || herbicide[ny][nx]> 0) continue; + tmp[ny][nx] += reproduction; + } + } + } + map = tmp; + } + + private static void growUp() { + for (int i = 0; i < N; i++) { + for (int j = 0; j < N; j++) { + if(map[i][j] <= 0) continue; + for (int d = 0; d < 4; d++) { + int ny = i + DIR[d][0]; + int nx = j + DIR[d][1]; + if(!inRange(ny, nx) || map[ny][nx] <= 0) continue; + map[i][j] += 1; + } + } + } + } + + private static int solve() { + int removedTree = 0; + + while (M--> 0) { + reduceHerbicide(); + growUp(); + reproduce(); + removedTree += sprayHerbicide(); + } + + return removedTree; + } + + 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()); + K = Integer.parseInt(st.nextToken()); + C = Integer.parseInt(st.nextToken()); + + herbicide = new int[N][N]; + map = new int[N][N]; + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < N; j++) { + map[i][j] = Integer.parseInt(st.nextToken()); + } + } + System.out.println(solve()); + } +} From 37d12a8a75036a7f426ece4a49bc486f5c6159f0 Mon Sep 17 00:00:00 2001 From: Jimin Date: 2025年3月27日 09:41:51 +0900 Subject: [PATCH 2/4] =?UTF-8?q?=EC=86=90=EC=A7=80=EB=AF=BC=20[BOJ]=20?= =?UTF-8?q?=ED=83=80=EC=9D=BC=20=EC=B1=84=EC=9A=B0=EA=B8=B03=5F250327?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "BOJ/10001-15000353円262円210円/JM_14852.java" | 35 +++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 "BOJ/10001-15000353円262円210円/JM_14852.java" diff --git "a/BOJ/10001-15000353円262円210円/JM_14852.java" "b/BOJ/10001-15000353円262円210円/JM_14852.java" new file mode 100644 index 00000000..49f58925 --- /dev/null +++ "b/BOJ/10001-15000353円262円210円/JM_14852.java" @@ -0,0 +1,35 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +public class JM_14852 { + static int N; + static final int MOD = 1_000_000_007; + + private static long solve() { + if(N == 1) return 2; + else if(N == 2) return 7; + + long[] dp = new long[N + 1]; + long[] sum = new long[N + 1]; + + dp[1] = 2; + dp[2] = 7; + sum[2] = 1; + + for (int i = 3; i <= N; i++) { + sum[i] = (dp[i - 3] + sum[i - 1]) % MOD; + dp[i] = (2 * dp[i - 1] + 3 * dp[i - 2] + 2 * sum[i]) % MOD; + } + + return dp[N]; + } + + 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()); + System.out.println(solve()); + } +} From 3b6d74f74d12f6cba1a61134efc63df65147ea43 Mon Sep 17 00:00:00 2001 From: Jimin Date: 2025年3月27日 10:47:12 +0900 Subject: [PATCH 3/4] =?UTF-8?q?=EC=86=90=EC=A7=80=EB=AF=BC=20[BOJ]=20?= =?UTF-8?q?=EC=86=8C=EC=88=98=EC=9D=98=20=EC=97=B0=EC=86=8D=ED=95=A9=5F250?= =?UTF-8?q?327?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "BOJ/1000-5000353円262円210円/JM_1644.java" | 56 ++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 "BOJ/1000-5000353円262円210円/JM_1644.java" diff --git "a/BOJ/1000-5000353円262円210円/JM_1644.java" "b/BOJ/1000-5000353円262円210円/JM_1644.java" new file mode 100644 index 00000000..c188263a --- /dev/null +++ "b/BOJ/1000-5000353円262円210円/JM_1644.java" @@ -0,0 +1,56 @@ +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 java.util.StringTokenizer; + +public class JM_1644 { + static int N; + static List primeNumbers; + + private static void findPrimeNumber() { + boolean[] isPrime = new boolean[N + 1]; + Arrays.fill(isPrime, true); + + for (int i = 2; i <= Math.sqrt(N); i++) { + if(!isPrime[i]) continue; + for(int j = i * i; j <= N; j += i) { + isPrime[j] = false; + } + } + + for (int i = 2; i <= N; i++) { + if(isPrime[i]) primeNumbers.add(i); + } + } + + private static int solve() { + primeNumbers = new ArrayList(); + findPrimeNumber(); + + int count = 0; + int lo = 0, hi = 0; + int sum = 0; + while (true) { + if(sum < N) { + if(hi == primeNumbers.size()) break; + sum += primeNumbers.get(hi++); + } + else { + sum -= primeNumbers.get(lo++); + } + + if(sum == N) count++; + } + return count; + } + + 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()); + System.out.println(solve()); + } +} From fde73ec0a5baef78718bacb7edd986e5e80055ef Mon Sep 17 00:00:00 2001 From: Jimin Date: 2025年3月29日 11:44:20 +0900 Subject: [PATCH 4/4] =?UTF-8?q?=EC=86=90=EC=A7=80=EB=AF=BC=20[PG]=20?= =?UTF-8?q?=ED=95=A9=EC=8A=B9=ED=83=9D=EC=8B=9C=5F250329?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Programmers/Level3/JM_ 72413.java | 50 +++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 Programmers/Level3/JM_ 72413.java diff --git a/Programmers/Level3/JM_ 72413.java b/Programmers/Level3/JM_ 72413.java new file mode 100644 index 00000000..cc977944 --- /dev/null +++ b/Programmers/Level3/JM_ 72413.java @@ -0,0 +1,50 @@ +public class JM_72413 { + static final int INF = Integer.MAX_VALUE; + static int[][] edge; + + public static int floydWarshall(int n, int s, int a, int b) { + for(int k = 1; k <= n; k++) { + for(int i = 1; i <= n; i++) { + if(edge[i][k] == INF) continue; + for(int j = 1; j <= n; j++) { + if(edge[k][j] == INF) continue; + if(edge[i][j]> edge[i][k] + edge[k][j]) { + edge[i][j] = edge[i][k] + edge[k][j]; + } + } + } + } + + int answer = Math.min(INF, edge[s][a] + edge[s][b]); + for(int i = 1; i <= n; i++) { + if(i == s) continue; + int cost = Math.min(INF, edge[s][i] + edge[i][a] + edge[i][b]); + answer = Math.min(answer, cost); + } + + return answer; + } + + public static int solution(int n, int s, int a, int b, int[][] fares) { + edge = new int[n + 1][n + 1]; + + for(int i = 1; i <= n; i++) { + for(int j = 1; j <= n; j++) { + if(i != j) edge[i][j] = INF; + } + } + + for(int[] fare : fares) { + edge[fare[0]][fare[1]] = fare[2]; + edge[fare[1]][fare[0]] = fare[2]; + } + + return floydWarshall(n, s, a, b); + } + + public static void main(String[] args) { + System.out.println(solution(6, 4, 6, 2, new int[][] {{4, 1, 10}, {3, 5, 24}, {5, 6, 2}, {3, 1, 41}, {5, 1, 24}, {4, 6, 50}, {2, 4, 66}, {2, 3, 22}, {1, 6, 25}})); + System.out.println(solution(7, 3, 4, 1, new int[][] {{5, 7, 9}, {4, 6, 4}, {3, 6, 1}, {3, 2, 3}, {2, 1, 6}})); + System.out.println(solution(6, 4, 5, 6, new int[][] {{2,6,6}, {6,3,7}, {4,6,7}, {6,5,11}, {2,5,12}, {5,3,20}, {2,4,8}, {4,3,9}})); + } +}

AltStyle によって変換されたページ (->オリジナル) /