From f8ed7aeb0b91a9742ebe4cf4ecfda00839955d08 Mon Sep 17 00:00:00 2001 From: jung0115 Date: Mon, 23 Sep 2024 21:41:54 +0900 Subject: [PATCH 01/23] 2024-09-23 --- jung0115/.gitignore | 3 +- jung0115/README.md | 3 +- .../Baekjoon_1256.java" | 55 +++++++++++++++++++ .../Baekjoon_1563.kt" | 0 .../Baekjoon_2624.kt" | 0 5 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 "jung0115/\353\213\244\354\235\264\353\202\230\353\257\271\355\224\204\353\241\234\352\267\270\353\236\230\353\260\215/Baekjoon_1256.java" rename "jung0115/\353\213\244\354\235\264\353\202\230\353\257\271 \355\224\204\353\241\234\352\267\270\353\236\230\353\260\215/Baekjoon_1563.kt" => "jung0115/\353\213\244\354\235\264\353\202\230\353\257\271\355\224\204\353\241\234\352\267\270\353\236\230\353\260\215/Baekjoon_1563.kt" (100%) rename "jung0115/\353\213\244\354\235\264\353\202\230\353\257\271 \355\224\204\353\241\234\352\267\270\353\236\230\353\260\215/Baekjoon_2624.kt" => "jung0115/\353\213\244\354\235\264\353\202\230\353\257\271\355\224\204\353\241\234\352\267\270\353\236\230\353\260\215/Baekjoon_2624.kt" (100%) diff --git a/jung0115/.gitignore b/jung0115/.gitignore index 01345c6f..64223e8b 100644 --- a/jung0115/.gitignore +++ b/jung0115/.gitignore @@ -1,2 +1,3 @@ *.jars -*.jar \ No newline at end of file +*.jar +*.class \ No newline at end of file diff --git a/jung0115/README.md b/jung0115/README.md index 2d2a0ce1..86e688b2 100644 --- a/jung0115/README.md +++ b/jung0115/README.md @@ -13,4 +13,5 @@ | 9차시 | 2024.08.27.화 | 수학 | [음식 평론가(1188)](https://www.acmicpc.net/problem/1188) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/150 | | 10차시 | 2024.08.28.수 | 브루트포스 | [램프(1034)](https://www.acmicpc.net/problem/1034) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/151 | | 11차시 | 2024.09.04.수 | 수학 | [축구(1344)](https://www.acmicpc.net/problem/1344) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/153 | -| 12차시 | 2024.09.07.토 | 다이나믹 프로그래밍 | [개근상(1563)](https://www.acmicpc.net/problem/1563) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/157 | \ No newline at end of file +| 12차시 | 2024.09.07.토 | 다이나믹 프로그래밍 | [개근상(1563)](https://www.acmicpc.net/problem/1563) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/157 | +| 13차시 | 2024.09.23.월 | 다이나믹 프로그래밍 | [사전(1256)](https://www.acmicpc.net/problem/1256) | | \ No newline at end of file diff --git "a/jung0115/\353\213\244\354\235\264\353\202\230\353\257\271\355\224\204\353\241\234\352\267\270\353\236\230\353\260\215/Baekjoon_1256.java" "b/jung0115/\353\213\244\354\235\264\353\202\230\353\257\271\355\224\204\353\241\234\352\267\270\353\236\230\353\260\215/Baekjoon_1256.java" new file mode 100644 index 00000000..40dc87a1 --- /dev/null +++ "b/jung0115/\353\213\244\354\235\264\353\202\230\353\257\271\355\224\204\353\241\234\352\267\270\353\236\230\353\260\215/Baekjoon_1256.java" @@ -0,0 +1,55 @@ +package jung0115.다이나믹프로그래밍; +// 13차시 2024.09.23.월 : 백준 - 사전(1256) + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +public class Baekjoon_1256 { + public static void main(String[] args) throws IOException { + BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(bf.readLine()); + + int N = Integer.parseInt(st.nextToken()); // a의 개수 + int M = Integer.parseInt(st.nextToken()); // z의 개수 + int K = Integer.parseInt(st.nextToken()); // 몇 번째 문자열을 찾아야 하는지 + + StringBuilder answer = new StringBuilder(); + + long[][] dp = new long[ N + M + 1 ][ N + M + 1 ]; + dp[0][0] = 1; + + for(int i = 1;i <= N + M; i++){ + dp[i][0] = 1; + dp[i][i] = 1; + for(int j = 1; j < i; j++){ + dp[i][j] = dp[i-1][j-1] + dp[i-1][j]; + + if(dp[i][j] > 1000000000) + dp[i][j] = 1000000001; + } + } + + // 사전에 수록되어 있는 문자열의 개수가 K보다 작을 경우 + if(dp[N + M][N] < K) { + answer.append("-1"); + } + else { + while (N != 0 || M != 0) { + if(dp[N + M - 1][M] >= K) { + answer.append("a"); + N--; + } + else { + answer.append("z"); + K -= dp[N + M - 1][M]; + M--; + } + } + } + + System.out.print(answer); + + } +} diff --git "a/jung0115/\353\213\244\354\235\264\353\202\230\353\257\271 \355\224\204\353\241\234\352\267\270\353\236\230\353\260\215/Baekjoon_1563.kt" "b/jung0115/\353\213\244\354\235\264\353\202\230\353\257\271\355\224\204\353\241\234\352\267\270\353\236\230\353\260\215/Baekjoon_1563.kt" similarity index 100% rename from "jung0115/\353\213\244\354\235\264\353\202\230\353\257\271 \355\224\204\353\241\234\352\267\270\353\236\230\353\260\215/Baekjoon_1563.kt" rename to "jung0115/\353\213\244\354\235\264\353\202\230\353\257\271\355\224\204\353\241\234\352\267\270\353\236\230\353\260\215/Baekjoon_1563.kt" diff --git "a/jung0115/\353\213\244\354\235\264\353\202\230\353\257\271 \355\224\204\353\241\234\352\267\270\353\236\230\353\260\215/Baekjoon_2624.kt" "b/jung0115/\353\213\244\354\235\264\353\202\230\353\257\271\355\224\204\353\241\234\352\267\270\353\236\230\353\260\215/Baekjoon_2624.kt" similarity index 100% rename from "jung0115/\353\213\244\354\235\264\353\202\230\353\257\271 \355\224\204\353\241\234\352\267\270\353\236\230\353\260\215/Baekjoon_2624.kt" rename to "jung0115/\353\213\244\354\235\264\353\202\230\353\257\271\355\224\204\353\241\234\352\267\270\353\236\230\353\260\215/Baekjoon_2624.kt" From 9acd0df189043ee25a25576830541eb194daad8b Mon Sep 17 00:00:00 2001 From: jung0115 Date: Mon, 23 Sep 2024 21:45:08 +0900 Subject: [PATCH 02/23] 2024-09-23 readme --- jung0115/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jung0115/README.md b/jung0115/README.md index 86e688b2..95433a2d 100644 --- a/jung0115/README.md +++ b/jung0115/README.md @@ -14,4 +14,4 @@ | 10차시 | 2024.08.28.수 | 브루트포스 | [램프(1034)](https://www.acmicpc.net/problem/1034) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/151 | | 11차시 | 2024.09.04.수 | 수학 | [축구(1344)](https://www.acmicpc.net/problem/1344) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/153 | | 12차시 | 2024.09.07.토 | 다이나믹 프로그래밍 | [개근상(1563)](https://www.acmicpc.net/problem/1563) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/157 | -| 13차시 | 2024.09.23.월 | 다이나믹 프로그래밍 | [사전(1256)](https://www.acmicpc.net/problem/1256) | | \ No newline at end of file +| 13차시 | 2024.09.23.월 | 다이나믹 프로그래밍 | [사전(1256)](https://www.acmicpc.net/problem/1256) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/162 | \ No newline at end of file From 2a2871b15625198df78e74fc2542ce5c3dbcca57 Mon Sep 17 00:00:00 2001 From: jung0115 Date: Tue, 24 Sep 2024 11:04:56 +0900 Subject: [PATCH 03/23] 2024-09-23 update: --- .../Baekjoon_1256.java" | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git "a/jung0115/\353\213\244\354\235\264\353\202\230\353\257\271\355\224\204\353\241\234\352\267\270\353\236\230\353\260\215/Baekjoon_1256.java" "b/jung0115/\353\213\244\354\235\264\353\202\230\353\257\271\355\224\204\353\241\234\352\267\270\353\236\230\353\260\215/Baekjoon_1256.java" index 40dc87a1..c091d097 100644 --- "a/jung0115/\353\213\244\354\235\264\353\202\230\353\257\271\355\224\204\353\241\234\352\267\270\353\236\230\353\260\215/Baekjoon_1256.java" +++ "b/jung0115/\353\213\244\354\235\264\353\202\230\353\257\271\355\224\204\353\241\234\352\267\270\353\236\230\353\260\215/Baekjoon_1256.java" @@ -32,7 +32,7 @@ public static void main(String[] args) throws IOException { } // 사전에 수록되어 있는 문자열의 개수가 K보다 작을 경우 - if(dp[N + M][N] < K) { + if(dp[N + M][M] < K) { answer.append("-1"); } else { From 90789664321baa0ec717ce717e03d0c98faccbea Mon Sep 17 00:00:00 2001 From: jung0115 Date: Thu, 26 Sep 2024 00:29:04 +0900 Subject: [PATCH 04/23] 2024-09-26 --- jung0115/README.md | 3 +- .../Baekjoon_1781.java" | 66 +++++++++++++++++++ .../Baekjoon_1781_fail.java" | 37 +++++++++++ 3 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 "jung0115/\352\267\270\353\246\254\353\224\224\354\225\214\352\263\240\353\246\254\354\246\230/Baekjoon_1781.java" create mode 100644 "jung0115/\352\267\270\353\246\254\353\224\224\354\225\214\352\263\240\353\246\254\354\246\230/Baekjoon_1781_fail.java" diff --git a/jung0115/README.md b/jung0115/README.md index 95433a2d..cf0b919a 100644 --- a/jung0115/README.md +++ b/jung0115/README.md @@ -14,4 +14,5 @@ | 10차시 | 2024.08.28.수 | 브루트포스 | [램프(1034)](https://www.acmicpc.net/problem/1034) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/151 | | 11차시 | 2024.09.04.수 | 수학 | [축구(1344)](https://www.acmicpc.net/problem/1344) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/153 | | 12차시 | 2024.09.07.토 | 다이나믹 프로그래밍 | [개근상(1563)](https://www.acmicpc.net/problem/1563) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/157 | -| 13차시 | 2024.09.23.월 | 다이나믹 프로그래밍 | [사전(1256)](https://www.acmicpc.net/problem/1256) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/162 | \ No newline at end of file +| 13차시 | 2024.09.23.월 | 다이나믹 프로그래밍 | [사전(1256)](https://www.acmicpc.net/problem/1256) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/162 | +| 14차시 | 2024.09.25.수 | 그리디 알고리즘 | [컵라면(1781)](https://www.acmicpc.net/problem/1781) | | \ No newline at end of file diff --git "a/jung0115/\352\267\270\353\246\254\353\224\224\354\225\214\352\263\240\353\246\254\354\246\230/Baekjoon_1781.java" "b/jung0115/\352\267\270\353\246\254\353\224\224\354\225\214\352\263\240\353\246\254\354\246\230/Baekjoon_1781.java" new file mode 100644 index 00000000..9444d359 --- /dev/null +++ "b/jung0115/\352\267\270\353\246\254\353\224\224\354\225\214\352\263\240\353\246\254\354\246\230/Baekjoon_1781.java" @@ -0,0 +1,66 @@ +// 14차시 2024.09.25.수 : 백준 - 컵라면(1781) +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; +import java.util.Arrays; +import java.util.PriorityQueue; + +public class Baekjoon_1781 { + static class CupNoodle implements Comparable { + int deadLine; + int count; + + public CupNoodle(int deadLine, int count) { + this.deadLine = deadLine; + this.count = count; + } + + @Override + public int compareTo(CupNoodle o) { + // 데드라인을 기준으로 오름차순 정렬 + return this.deadLine - o.deadLine; + } + } + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + int N = Integer.parseInt(br.readLine()); + + CupNoodle[] cupNoodles = new CupNoodle[N]; + + for (int i = 0; i < N; i++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + + int deadLine = Integer.parseInt(st.nextToken()); // 데드라인 + int count = Integer.parseInt(st.nextToken()); // 맞힐 때 받는 컵라면 수 + + cupNoodles[i] = new CupNoodle(deadLine, count); + } + + // 데드라인을 기준으로 정렬 (오름차순) + Arrays.sort(cupNoodles); + + PriorityQueue pq = new PriorityQueue<>(); + + for (CupNoodle cn : cupNoodles) { + // 만약 현재 데드라인 내에 풀 수 있는 문제라면 큐에 추가 + pq.offer(cn.count); + + // 큐의 크기가 데드라인을 초과하면 가장 적은 컵라면 수를 제거 + if (pq.size() > cn.deadLine) { + pq.poll(); + } + } + + int answer = 0; + + // 큐에 남아 있는 컵라면의 총합을 구함 + while (!pq.isEmpty()) { + answer += pq.poll(); + } + + System.out.println(answer); + } +} diff --git "a/jung0115/\352\267\270\353\246\254\353\224\224\354\225\214\352\263\240\353\246\254\354\246\230/Baekjoon_1781_fail.java" "b/jung0115/\352\267\270\353\246\254\353\224\224\354\225\214\352\263\240\353\246\254\354\246\230/Baekjoon_1781_fail.java" new file mode 100644 index 00000000..95a52258 --- /dev/null +++ "b/jung0115/\352\267\270\353\246\254\353\224\224\354\225\214\352\263\240\353\246\254\354\246\230/Baekjoon_1781_fail.java" @@ -0,0 +1,37 @@ +// 14차시 2024.09.25.수 : 백준 - 컵라면(1781) +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; +import java.util.HashMap; +import java.util.Iterator; + +public class Baekjoon_1781_fail { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + int N = Integer.parseInt(br.readLine()); + + HashMap cupNoodles = new HashMap(); + + for(int i = 0; i < N; i++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + + int deadLine = Integer.parseInt(st.nextToken()); // 데드라인 + int count = Integer.parseInt(st.nextToken()); // 맞힐 때 받는 컵라면 수 + + int current = cupNoodles.getOrDefault(deadLine, 0); + if(current < count) cupNoodles.put(deadLine, count); + } + + int answer = 0; + + Iterator keys = cupNoodles.keySet().iterator(); + while(keys.hasNext()){ + int key = keys.next(); + answer += cupNoodles.get(key); + } + + System.out.print(answer); + } +} From b2f729f6a8c7785420fc4c038ac6e6731c6c0f68 Mon Sep 17 00:00:00 2001 From: jung0115 Date: Thu, 26 Sep 2024 00:30:23 +0900 Subject: [PATCH 05/23] 2024-09-26 readme --- jung0115/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jung0115/README.md b/jung0115/README.md index cf0b919a..d434c325 100644 --- a/jung0115/README.md +++ b/jung0115/README.md @@ -15,4 +15,4 @@ | 11차시 | 2024.09.04.수 | 수학 | [축구(1344)](https://www.acmicpc.net/problem/1344) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/153 | | 12차시 | 2024.09.07.토 | 다이나믹 프로그래밍 | [개근상(1563)](https://www.acmicpc.net/problem/1563) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/157 | | 13차시 | 2024.09.23.월 | 다이나믹 프로그래밍 | [사전(1256)](https://www.acmicpc.net/problem/1256) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/162 | -| 14차시 | 2024.09.25.수 | 그리디 알고리즘 | [컵라면(1781)](https://www.acmicpc.net/problem/1781) | | \ No newline at end of file +| 14차시 | 2024.09.25.수 | 그리디 알고리즘 | [컵라면(1781)](https://www.acmicpc.net/problem/1781) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/165 | \ No newline at end of file From 3205c134e83497ed153b983e6ed4bc7fce805af7 Mon Sep 17 00:00:00 2001 From: jung0115 Date: Sat, 28 Sep 2024 03:08:16 +0900 Subject: [PATCH 06/23] 2024-09-28 --- jung0115/README.md | 3 +- .../Baekjoon_12015.java" | 55 +++++++++++++++++++ .../Baekjoon_1477.kt" | 0 .../Programmers_43238.kt" | 0 4 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 "jung0115/\354\235\264\353\266\204\355\203\220\354\203\211/Baekjoon_12015.java" rename "jung0115/\354\235\264\353\266\204 \355\203\220\354\203\211/Baekjoon_1477.kt" => "jung0115/\354\235\264\353\266\204\355\203\220\354\203\211/Baekjoon_1477.kt" (100%) rename "jung0115/\354\235\264\353\266\204 \355\203\220\354\203\211/Programmers_43238.kt" => "jung0115/\354\235\264\353\266\204\355\203\220\354\203\211/Programmers_43238.kt" (100%) diff --git a/jung0115/README.md b/jung0115/README.md index d434c325..91937fe3 100644 --- a/jung0115/README.md +++ b/jung0115/README.md @@ -15,4 +15,5 @@ | 11차시 | 2024.09.04.수 | 수학 | [축구(1344)](https://www.acmicpc.net/problem/1344) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/153 | | 12차시 | 2024.09.07.토 | 다이나믹 프로그래밍 | [개근상(1563)](https://www.acmicpc.net/problem/1563) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/157 | | 13차시 | 2024.09.23.월 | 다이나믹 프로그래밍 | [사전(1256)](https://www.acmicpc.net/problem/1256) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/162 | -| 14차시 | 2024.09.25.수 | 그리디 알고리즘 | [컵라면(1781)](https://www.acmicpc.net/problem/1781) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/165 | \ No newline at end of file +| 14차시 | 2024.09.25.수 | 그리디 알고리즘 | [컵라면(1781)](https://www.acmicpc.net/problem/1781) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/165 | +| 15차시 | 2024.09.28.토 | 이분 탐색 | [가장 긴 증가하는 부분 수열 2(12015)](https://www.acmicpc.net/problem/12015) | | \ No newline at end of file diff --git "a/jung0115/\354\235\264\353\266\204\355\203\220\354\203\211/Baekjoon_12015.java" "b/jung0115/\354\235\264\353\266\204\355\203\220\354\203\211/Baekjoon_12015.java" new file mode 100644 index 00000000..afef76f8 --- /dev/null +++ "b/jung0115/\354\235\264\353\266\204\355\203\220\354\203\211/Baekjoon_12015.java" @@ -0,0 +1,55 @@ +package jung0115.이분탐색; +// 15차시 2024.09.28.토 : 백준 - 가장 긴 증가하는 부분 수열 2(12015) + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +public class Baekjoon_12015 { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + int N = Integer.parseInt(br.readLine()); + StringTokenizer st = new StringTokenizer(br.readLine()); + + int[] A = new int[N]; + for(int i = 0; i < N; i++) { + A[i] = Integer.parseInt(st.nextToken()); + } + + int[] longIncrease = new int[N]; + int lastIndex = 0; + longIncrease[lastIndex] = A[0]; + + for(int i = 1; i < N; i++) { + int num = A[i]; + + // 이전값보다 큼 -> 증가 + if(longIncrease[lastIndex] < num) { + longIncrease[++lastIndex] = num; + } + // 이전값보다 작음 + else { + int left = 0; + int right = lastIndex + 1; + + while (left < right) { + int mid = (left + right) / 2; + + if(longIncrease[mid] < num) { + left = mid + 1; + } + else { + right = mid; + } + } + + // num보다 작은 값 중 제일 뒤에 있는 숫자의 뒤 + longIncrease[left] = num; + } + } + + System.out.print(lastIndex + 1); + } +} diff --git "a/jung0115/\354\235\264\353\266\204 \355\203\220\354\203\211/Baekjoon_1477.kt" "b/jung0115/\354\235\264\353\266\204\355\203\220\354\203\211/Baekjoon_1477.kt" similarity index 100% rename from "jung0115/\354\235\264\353\266\204 \355\203\220\354\203\211/Baekjoon_1477.kt" rename to "jung0115/\354\235\264\353\266\204\355\203\220\354\203\211/Baekjoon_1477.kt" diff --git "a/jung0115/\354\235\264\353\266\204 \355\203\220\354\203\211/Programmers_43238.kt" "b/jung0115/\354\235\264\353\266\204\355\203\220\354\203\211/Programmers_43238.kt" similarity index 100% rename from "jung0115/\354\235\264\353\266\204 \355\203\220\354\203\211/Programmers_43238.kt" rename to "jung0115/\354\235\264\353\266\204\355\203\220\354\203\211/Programmers_43238.kt" From 84d1ad0d63e4454ed858dd38b10c3ad28b2718b1 Mon Sep 17 00:00:00 2001 From: jung0115 Date: Sat, 28 Sep 2024 03:09:06 +0900 Subject: [PATCH 07/23] 2024-09-28 readme --- jung0115/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jung0115/README.md b/jung0115/README.md index 91937fe3..613247fd 100644 --- a/jung0115/README.md +++ b/jung0115/README.md @@ -16,4 +16,4 @@ | 12차시 | 2024.09.07.토 | 다이나믹 프로그래밍 | [개근상(1563)](https://www.acmicpc.net/problem/1563) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/157 | | 13차시 | 2024.09.23.월 | 다이나믹 프로그래밍 | [사전(1256)](https://www.acmicpc.net/problem/1256) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/162 | | 14차시 | 2024.09.25.수 | 그리디 알고리즘 | [컵라면(1781)](https://www.acmicpc.net/problem/1781) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/165 | -| 15차시 | 2024.09.28.토 | 이분 탐색 | [가장 긴 증가하는 부분 수열 2(12015)](https://www.acmicpc.net/problem/12015) | | \ No newline at end of file +| 15차시 | 2024.09.28.토 | 이분 탐색 | [가장 긴 증가하는 부분 수열 2(12015)](https://www.acmicpc.net/problem/12015) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/169 | \ No newline at end of file From 8bec559130fede2ea75e016eba12c2880c1a3d4b Mon Sep 17 00:00:00 2001 From: jung0115 Date: Sat, 5 Oct 2024 23:45:47 +0900 Subject: [PATCH 08/23] 2024-10-05 --- jung0115/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/jung0115/README.md b/jung0115/README.md index 613247fd..cea45c43 100644 --- a/jung0115/README.md +++ b/jung0115/README.md @@ -16,4 +16,5 @@ | 12차시 | 2024.09.07.토 | 다이나믹 프로그래밍 | [개근상(1563)](https://www.acmicpc.net/problem/1563) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/157 | | 13차시 | 2024.09.23.월 | 다이나믹 프로그래밍 | [사전(1256)](https://www.acmicpc.net/problem/1256) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/162 | | 14차시 | 2024.09.25.수 | 그리디 알고리즘 | [컵라면(1781)](https://www.acmicpc.net/problem/1781) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/165 | -| 15차시 | 2024.09.28.토 | 이분 탐색 | [가장 긴 증가하는 부분 수열 2(12015)](https://www.acmicpc.net/problem/12015) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/169 | \ No newline at end of file +| 15차시 | 2024.09.28.토 | 이분 탐색 | [가장 긴 증가하는 부분 수열 2(12015)](https://www.acmicpc.net/problem/12015) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/169 | +| 16차시 | 2024.10.05.토 | 시뮬레이션 | [주차 요금 계산(Lv.2)](https://school.programmers.co.kr/learn/courses/30/lessons/92341) | | \ No newline at end of file From 15f88a1b1926dde2be5c16659b92c70c5b6a7480 Mon Sep 17 00:00:00 2001 From: jung0115 Date: Sat, 5 Oct 2024 23:48:53 +0900 Subject: [PATCH 09/23] 2024-10-05 --- .../Programmers_92341.kt" | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 "jung0115/\354\213\234\353\256\254\353\240\210\354\235\264\354\205\230/Programmers_92341.kt" diff --git "a/jung0115/\354\213\234\353\256\254\353\240\210\354\235\264\354\205\230/Programmers_92341.kt" "b/jung0115/\354\213\234\353\256\254\353\240\210\354\235\264\354\205\230/Programmers_92341.kt" new file mode 100644 index 00000000..c6216b4e --- /dev/null +++ "b/jung0115/\354\213\234\353\256\254\353\240\210\354\235\264\354\205\230/Programmers_92341.kt" @@ -0,0 +1,71 @@ +// 16차시 2024.10.05.토 : 프로그래머스 - 주차 요금 계산(Lv.2) +import java.util.HashMap + +data class Record ( + val time: Int, + val carNum: Int, + val isIn: Boolean +) + +class Solution { + fun solution(fees: IntArray, records: Array): IntArray { + val sortRecords: MutableList = mutableListOf() + + // 주어진 기록을 파싱해서 Record 리스트로 변환 + for(record: String in records) { + val current = record.split(" ") + + val timeSplit = current[0].split(":") + val time: Int = timeSplit[0].toInt() * 60 + timeSplit[1].toInt() + val carNum: Int = current[1].toInt() + val isIn: Boolean = current[2] == "IN" + + sortRecords.add(Record(time, carNum, isIn)) + } + + // 입차 중인 차량들의 입차 시간을 저장하는 맵 + val inCars: HashMap = HashMap() + // 자동차 번호별 총 주차 시간을 저장하는 맵 + val parkingTimes: HashMap = HashMap() + + // 각 레코드를 처리 + for(record: Record in sortRecords) { + if (record.isIn) { + // 입차 시 입차 시간을 기록 + inCars[record.carNum] = record.time + } else { + // 출차 시 주차 시간을 계산하고 누적 + val inTime: Int = inCars.remove(record.carNum) ?: 0 + val parkingTime = record.time - inTime + parkingTimes[record.carNum] = parkingTimes.getOrDefault(record.carNum, 0) + parkingTime + } + } + + // 출차하지 않은 차량은 23:59에 출차된 것으로 간주 + val endTime = 23 * 60 + 59 + for((carNum, inTime) in inCars) { + val parkingTime = endTime - inTime + parkingTimes[carNum] = parkingTimes.getOrDefault(carNum, 0) + parkingTime + } + + // 자동차 번호 순으로 결과를 계산 + val result: MutableList> = mutableListOf() + for((carNum, parkingTime) in parkingTimes) { + var cost: Int = fees[1] // 기본 요금 + val overTime = parkingTime - fees[0] + + // 기본 시간을 넘은 경우 추가 요금을 계산 + if (overTime > 0) { + cost += (overTime / fees[2]) * fees[3] + if (overTime % fees[2] > 0) { + cost += fees[3] + } + } + + result.add(Pair(carNum, cost)) + } + + // 자동차 번호 순으로 정렬 후 요금만 반환 + return result.sortedBy { it.first }.map { it.second }.toIntArray() + } +} \ No newline at end of file From fec78c0ffd6e1a14d7f38d64007e6626b407d929 Mon Sep 17 00:00:00 2001 From: jung0115 Date: Sat, 5 Oct 2024 23:50:25 +0900 Subject: [PATCH 10/23] 2024-10-05 readme --- jung0115/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jung0115/README.md b/jung0115/README.md index cea45c43..3e266146 100644 --- a/jung0115/README.md +++ b/jung0115/README.md @@ -17,4 +17,4 @@ | 13차시 | 2024.09.23.월 | 다이나믹 프로그래밍 | [사전(1256)](https://www.acmicpc.net/problem/1256) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/162 | | 14차시 | 2024.09.25.수 | 그리디 알고리즘 | [컵라면(1781)](https://www.acmicpc.net/problem/1781) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/165 | | 15차시 | 2024.09.28.토 | 이분 탐색 | [가장 긴 증가하는 부분 수열 2(12015)](https://www.acmicpc.net/problem/12015) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/169 | -| 16차시 | 2024.10.05.토 | 시뮬레이션 | [주차 요금 계산(Lv.2)](https://school.programmers.co.kr/learn/courses/30/lessons/92341) | | \ No newline at end of file +| 16차시 | 2024.10.05.토 | 시뮬레이션 | [주차 요금 계산(Lv.2)](https://school.programmers.co.kr/learn/courses/30/lessons/92341) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/173 | \ No newline at end of file From a3699d1c900ce44f30dd0bc49cbbf49da1461a6a Mon Sep 17 00:00:00 2001 From: jung0115 Date: Fri, 11 Oct 2024 15:59:56 +0900 Subject: [PATCH 11/23] 2024-10-11 --- jung0115/README.md | 3 ++- .../Programmers_148653.kt" | 26 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 "jung0115/\352\267\270\353\246\254\353\224\224\354\225\214\352\263\240\353\246\254\354\246\230/Programmers_148653.kt" diff --git a/jung0115/README.md b/jung0115/README.md index 3e266146..a94da448 100644 --- a/jung0115/README.md +++ b/jung0115/README.md @@ -17,4 +17,5 @@ | 13차시 | 2024.09.23.월 | 다이나믹 프로그래밍 | [사전(1256)](https://www.acmicpc.net/problem/1256) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/162 | | 14차시 | 2024.09.25.수 | 그리디 알고리즘 | [컵라면(1781)](https://www.acmicpc.net/problem/1781) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/165 | | 15차시 | 2024.09.28.토 | 이분 탐색 | [가장 긴 증가하는 부분 수열 2(12015)](https://www.acmicpc.net/problem/12015) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/169 | -| 16차시 | 2024.10.05.토 | 시뮬레이션 | [주차 요금 계산(Lv.2)](https://school.programmers.co.kr/learn/courses/30/lessons/92341) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/173 | \ No newline at end of file +| 16차시 | 2024.10.05.토 | 시뮬레이션 | [주차 요금 계산(Lv.2)](https://school.programmers.co.kr/learn/courses/30/lessons/92341) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/173 | +| 17차시 | 2024.10.11.금 | 그리디 알고리즘 | [마법의 엘리베이터(Lv.2)](https://school.programmers.co.kr/learn/courses/30/lessons/148653) | | \ No newline at end of file diff --git "a/jung0115/\352\267\270\353\246\254\353\224\224\354\225\214\352\263\240\353\246\254\354\246\230/Programmers_148653.kt" "b/jung0115/\352\267\270\353\246\254\353\224\224\354\225\214\352\263\240\353\246\254\354\246\230/Programmers_148653.kt" new file mode 100644 index 00000000..1da1697b --- /dev/null +++ "b/jung0115/\352\267\270\353\246\254\353\224\224\354\225\214\352\263\240\353\246\254\354\246\230/Programmers_148653.kt" @@ -0,0 +1,26 @@ +// 17차시 2024.10.11.금 : 프로그래머스 - 마법의 엘리베이터(Lv.2) +class Solution { + fun solution(storey: Int): Int { + var answer: Int = 0 + var storeyClone = storey + + while (storeyClone > 0) { + val num = storeyClone % 10 + storeyClone /= 10 + + if (num < 5) { + answer += num + } else if (num == 5) { + // 5일 때, 다음 자릿수를 확인 + if (storeyClone % 10 >= 5) storeyClone++ + + answer += 5 + } else { + answer += (10 - num) + storeyClone++ + } + } + + return answer + } +} \ No newline at end of file From 3749b829acae1bad9187cb8ee5b5537b10de0414 Mon Sep 17 00:00:00 2001 From: jung0115 Date: Fri, 11 Oct 2024 16:01:19 +0900 Subject: [PATCH 12/23] 2024-10-11 readme --- jung0115/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jung0115/README.md b/jung0115/README.md index a94da448..7577f22d 100644 --- a/jung0115/README.md +++ b/jung0115/README.md @@ -18,4 +18,4 @@ | 14차시 | 2024.09.25.수 | 그리디 알고리즘 | [컵라면(1781)](https://www.acmicpc.net/problem/1781) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/165 | | 15차시 | 2024.09.28.토 | 이분 탐색 | [가장 긴 증가하는 부분 수열 2(12015)](https://www.acmicpc.net/problem/12015) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/169 | | 16차시 | 2024.10.05.토 | 시뮬레이션 | [주차 요금 계산(Lv.2)](https://school.programmers.co.kr/learn/courses/30/lessons/92341) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/173 | -| 17차시 | 2024.10.11.금 | 그리디 알고리즘 | [마법의 엘리베이터(Lv.2)](https://school.programmers.co.kr/learn/courses/30/lessons/148653) | | \ No newline at end of file +| 17차시 | 2024.10.11.금 | 그리디 알고리즘 | [마법의 엘리베이터(Lv.2)](https://school.programmers.co.kr/learn/courses/30/lessons/148653) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/175 | \ No newline at end of file From 5a6f8aef818e74800544876eaaa6b42e17659de8 Mon Sep 17 00:00:00 2001 From: jung0115 Date: Sat, 12 Oct 2024 22:24:00 +0900 Subject: [PATCH 13/23] 2024-10-12 --- jung0115/README.md | 3 +- .../Baekjoon_1135.kt" | 46 +++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 "jung0115/\353\213\244\354\235\264\353\202\230\353\257\271\355\224\204\353\241\234\352\267\270\353\236\230\353\260\215/Baekjoon_1135.kt" diff --git a/jung0115/README.md b/jung0115/README.md index 7577f22d..462f2572 100644 --- a/jung0115/README.md +++ b/jung0115/README.md @@ -18,4 +18,5 @@ | 14차시 | 2024.09.25.수 | 그리디 알고리즘 | [컵라면(1781)](https://www.acmicpc.net/problem/1781) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/165 | | 15차시 | 2024.09.28.토 | 이분 탐색 | [가장 긴 증가하는 부분 수열 2(12015)](https://www.acmicpc.net/problem/12015) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/169 | | 16차시 | 2024.10.05.토 | 시뮬레이션 | [주차 요금 계산(Lv.2)](https://school.programmers.co.kr/learn/courses/30/lessons/92341) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/173 | -| 17차시 | 2024.10.11.금 | 그리디 알고리즘 | [마법의 엘리베이터(Lv.2)](https://school.programmers.co.kr/learn/courses/30/lessons/148653) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/175 | \ No newline at end of file +| 17차시 | 2024.10.11.금 | 그리디 알고리즘 | [마법의 엘리베이터(Lv.2)](https://school.programmers.co.kr/learn/courses/30/lessons/148653) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/175 | +| 18차시 | 2024.10.12.토 | 다이나믹 프로그래밍 | [뉴스 전하기(1135)](https://www.acmicpc.net/problem/1135) | | \ No newline at end of file diff --git "a/jung0115/\353\213\244\354\235\264\353\202\230\353\257\271\355\224\204\353\241\234\352\267\270\353\236\230\353\260\215/Baekjoon_1135.kt" "b/jung0115/\353\213\244\354\235\264\353\202\230\353\257\271\355\224\204\353\241\234\352\267\270\353\236\230\353\260\215/Baekjoon_1135.kt" new file mode 100644 index 00000000..db2a4df4 --- /dev/null +++ "b/jung0115/\353\213\244\354\235\264\353\202\230\353\257\271\355\224\204\353\241\234\352\267\270\353\236\230\353\260\215/Baekjoon_1135.kt" @@ -0,0 +1,46 @@ +// 18차시 2024.10.12.토 : 백준 - 뉴스 전하기(1135) +import java.io.BufferedReader +import java.io.InputStreamReader +import java.util.StringTokenizer + +lateinit var employees: Array> +lateinit var dp: Array + +fun main() { + val br = BufferedReader(InputStreamReader(System.`in`)) + + var N = br.readLine().toInt() // 직원의 수 + + val st = StringTokenizer(br.readLine()) + employees = Array(N) { mutableListOf() } + dp = Array(N) { -1 } + + st.nextToken() + for(i: Int in 1..N-1) { + employees[st.nextToken().toInt()].add(i) + } + + println(dfs(0)) +} + +fun dfs(employee: Int): Int { + if (dp[employee] != -1) return dp[employee] + + // 더 이상 전화할 사람이 없음 + if (employees[employee].isEmpty()) return 0 + + // 자식들에게 전화하는 시간 + // 내림차순 정렬 + val times = employees[employee].map { dfs(it) }.sortedDescending() + + // 각 자식에게 전화 거는 시간 계산 + var maxTime = 0 + for (i in times.indices) { + // 자식에게 전화 + 그 자식이 전화 거는 시간 + maxTime = maxOf(maxTime, times[i] + i + 1) + } + + dp[employee] = maxTime + + return dp[employee] +} \ No newline at end of file From 5f9a77903969c77513505e0a4942ddfba9e15cbc Mon Sep 17 00:00:00 2001 From: jung0115 Date: Sat, 12 Oct 2024 22:24:37 +0900 Subject: [PATCH 14/23] 2024-10-12 readme --- jung0115/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jung0115/README.md b/jung0115/README.md index 462f2572..825382ae 100644 --- a/jung0115/README.md +++ b/jung0115/README.md @@ -19,4 +19,4 @@ | 15차시 | 2024.09.28.토 | 이분 탐색 | [가장 긴 증가하는 부분 수열 2(12015)](https://www.acmicpc.net/problem/12015) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/169 | | 16차시 | 2024.10.05.토 | 시뮬레이션 | [주차 요금 계산(Lv.2)](https://school.programmers.co.kr/learn/courses/30/lessons/92341) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/173 | | 17차시 | 2024.10.11.금 | 그리디 알고리즘 | [마법의 엘리베이터(Lv.2)](https://school.programmers.co.kr/learn/courses/30/lessons/148653) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/175 | -| 18차시 | 2024.10.12.토 | 다이나믹 프로그래밍 | [뉴스 전하기(1135)](https://www.acmicpc.net/problem/1135) | | \ No newline at end of file +| 18차시 | 2024.10.12.토 | 다이나믹 프로그래밍 | [뉴스 전하기(1135)](https://www.acmicpc.net/problem/1135) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/177 | \ No newline at end of file From f197b278fb6e61a9eddc2f6428eb6f6d630cac54 Mon Sep 17 00:00:00 2001 From: jung0115 Date: Wed, 16 Oct 2024 11:35:26 +0900 Subject: [PATCH 15/23] 2024-10-16 --- jung0115/README.md | 3 +- .../Programmers_60058.kt" | 77 +++++++++++++++++++ 2 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 "jung0115/\353\266\204\355\225\240\354\240\225\353\263\265/Programmers_60058.kt" diff --git a/jung0115/README.md b/jung0115/README.md index 825382ae..d8a02289 100644 --- a/jung0115/README.md +++ b/jung0115/README.md @@ -19,4 +19,5 @@ | 15차시 | 2024.09.28.토 | 이분 탐색 | [가장 긴 증가하는 부분 수열 2(12015)](https://www.acmicpc.net/problem/12015) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/169 | | 16차시 | 2024.10.05.토 | 시뮬레이션 | [주차 요금 계산(Lv.2)](https://school.programmers.co.kr/learn/courses/30/lessons/92341) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/173 | | 17차시 | 2024.10.11.금 | 그리디 알고리즘 | [마법의 엘리베이터(Lv.2)](https://school.programmers.co.kr/learn/courses/30/lessons/148653) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/175 | -| 18차시 | 2024.10.12.토 | 다이나믹 프로그래밍 | [뉴스 전하기(1135)](https://www.acmicpc.net/problem/1135) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/177 | \ No newline at end of file +| 18차시 | 2024.10.12.토 | 다이나믹 프로그래밍 | [뉴스 전하기(1135)](https://www.acmicpc.net/problem/1135) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/177 | +| 19차시 | 2024.10.16.수 | 분할정복 | [괄호 변환(Lv.2)](https://school.programmers.co.kr/learn/courses/30/lessons/60058) | | \ No newline at end of file diff --git "a/jung0115/\353\266\204\355\225\240\354\240\225\353\263\265/Programmers_60058.kt" "b/jung0115/\353\266\204\355\225\240\354\240\225\353\263\265/Programmers_60058.kt" new file mode 100644 index 00000000..492207d5 --- /dev/null +++ "b/jung0115/\353\266\204\355\225\240\354\240\225\353\263\265/Programmers_60058.kt" @@ -0,0 +1,77 @@ +// 프로그래머스 - 괄호 변환(Lv.2) +class Solution { + fun solution(p: String): String { + // 괄호를 숫자로 변환 + val numP = mutableListOf() + for(i: Int in 0..p.length - 1) { + if(p[i] == '(') numP.add(1) + else numP.add(-1) + } + + var answerList = divideString(numP) + + var answer = "" + + for(str in answerList) { + if(str == 1) answer += "(" + else answer += ")" + } + + return answer + } + + fun divideString(w: MutableList): MutableList { + // w가 빈 문자열이거나 올바른 괄호문자열인 경우 그대로 반환 + if(w.size == 0 || isCollect(w)) return w + + // 균형잡힌 괄호 문자열 u, v로 분리하기 + var checkSum: Int = 0 + + for(i: Int in 0..w.size - 1) { + checkSum += w[i] + + // 균형잡힌 괄호 문자열로 나뉘는 지점 + if(checkSum == 0) { + var u = w.subList(0, i + 1) + val v = divideString(w.subList(i + 1, w.size).toMutableList()) + + // u가 올바른 문자열일 경우 + if(isCollect(u)) { + u.addAll(v) + return u + } + // u가 올바른 문자열이 아닐 경우 + else { + var result = mutableListOf() + result.add(1) // 4-1. 빈 문자열에 첫 번째 문자로 '('를 붙입니다. + result.addAll(v) // 4-2. 문자열 v에 대해 1단계부터 재귀적으로 수행한 결과 문자열을 이어 붙입니다. + result.add(-1) // 4-3. ')'를 다시 붙입니다. + + // 4-4. u의 첫 번째와 마지막 문자를 제거하고, 나머지 문자열의 괄호 방향을 뒤집어서 뒤에 붙입니다. + u.removeAt(0) + u.removeAt(u.size - 1) + for(i: Int in 0..u.size - 1) { + u[i] *= -1 + } + + result.addAll(u) + + return result + } + } + } + + return w + } + + // 올바른 괄호 문자열인지 판단하는 함수 + fun isCollect(str: MutableList): Boolean { + var checkSum: Int = 0 + for(i: Int in 0..str.size - 1) { + checkSum += str[i] + + if(checkSum < 0) return false + } + return true + } +} \ No newline at end of file From 9656a93d7e389590a0db6aa521c400b3cca4ae56 Mon Sep 17 00:00:00 2001 From: jung0115 Date: Wed, 16 Oct 2024 11:36:12 +0900 Subject: [PATCH 16/23] 2024-10-16 readme --- jung0115/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jung0115/README.md b/jung0115/README.md index d8a02289..bf1fd33f 100644 --- a/jung0115/README.md +++ b/jung0115/README.md @@ -20,4 +20,4 @@ | 16차시 | 2024.10.05.토 | 시뮬레이션 | [주차 요금 계산(Lv.2)](https://school.programmers.co.kr/learn/courses/30/lessons/92341) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/173 | | 17차시 | 2024.10.11.금 | 그리디 알고리즘 | [마법의 엘리베이터(Lv.2)](https://school.programmers.co.kr/learn/courses/30/lessons/148653) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/175 | | 18차시 | 2024.10.12.토 | 다이나믹 프로그래밍 | [뉴스 전하기(1135)](https://www.acmicpc.net/problem/1135) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/177 | -| 19차시 | 2024.10.16.수 | 분할정복 | [괄호 변환(Lv.2)](https://school.programmers.co.kr/learn/courses/30/lessons/60058) | | \ No newline at end of file +| 19차시 | 2024.10.16.수 | 분할정복 | [괄호 변환(Lv.2)](https://school.programmers.co.kr/learn/courses/30/lessons/60058) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/178 | \ No newline at end of file From f5242d3a6aeca15c6a554cffd139354ea8a61b3b Mon Sep 17 00:00:00 2001 From: jung0115 Date: Sat, 19 Oct 2024 20:44:30 +0900 Subject: [PATCH 17/23] 2024-10-19 --- jung0115/README.md | 3 +- .../Programmers_64064.kt" | 57 +++++++++++++++++++ .../Programmers_60058.kt" | 2 +- 3 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 "jung0115/\353\260\261\355\212\270\353\236\230\355\202\271/Programmers_64064.kt" diff --git a/jung0115/README.md b/jung0115/README.md index bf1fd33f..63add7b1 100644 --- a/jung0115/README.md +++ b/jung0115/README.md @@ -20,4 +20,5 @@ | 16차시 | 2024.10.05.토 | 시뮬레이션 | [주차 요금 계산(Lv.2)](https://school.programmers.co.kr/learn/courses/30/lessons/92341) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/173 | | 17차시 | 2024.10.11.금 | 그리디 알고리즘 | [마법의 엘리베이터(Lv.2)](https://school.programmers.co.kr/learn/courses/30/lessons/148653) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/175 | | 18차시 | 2024.10.12.토 | 다이나믹 프로그래밍 | [뉴스 전하기(1135)](https://www.acmicpc.net/problem/1135) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/177 | -| 19차시 | 2024.10.16.수 | 분할정복 | [괄호 변환(Lv.2)](https://school.programmers.co.kr/learn/courses/30/lessons/60058) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/178 | \ No newline at end of file +| 19차시 | 2024.10.16.수 | 분할정복 | [괄호 변환(Lv.2)](https://school.programmers.co.kr/learn/courses/30/lessons/60058) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/178 | +| 20차시 | 2024.10.19.토 | 백트래킹 | [불량 사용자(Lv.3)](https://school.programmers.co.kr/learn/courses/30/lessons/64064) | | \ No newline at end of file diff --git "a/jung0115/\353\260\261\355\212\270\353\236\230\355\202\271/Programmers_64064.kt" "b/jung0115/\353\260\261\355\212\270\353\236\230\355\202\271/Programmers_64064.kt" new file mode 100644 index 00000000..6966c98a --- /dev/null +++ "b/jung0115/\353\260\261\355\212\270\353\236\230\355\202\271/Programmers_64064.kt" @@ -0,0 +1,57 @@ +// 20차시 2024.10.19.토 : 프로그래머스 - 불량 사용자(Lv.3) +import java.util.HashSet + +class Solution { + lateinit var userIdsClone: Array + lateinit var bannedIdsClone: Array + lateinit var collectIds: Array> + + val answer = HashSet>() + + fun solution(user_id: Array, banned_id: Array): Int { + userIdsClone = user_id.clone() + bannedIdsClone = banned_id.clone() + + collectIds = Array(banned_id.size) { mutableListOf() } + + // banned_id에 각각 올 수 있는 user_id 찾기 + for(i: Int in 0..banned_id.size - 1) { + for(j: Int in 0..user_id.size - 1) { + if(isCollect(banned_id[i], user_id[j])) { + collectIds[i].add(user_id[j]) + } + } + } + + dfs(HashSet(), 0) + + return answer.size + } + + fun dfs(set: HashSet, cnt: Int) { + if(cnt == collectIds.size) { + answer.add(HashSet(set)) + return + } + + for(userId in collectIds[cnt]) { + if(set.contains(userId)) continue + + set.add(userId) + dfs(set, cnt + 1) + set.remove(userId) + } + } + + fun isCollect(bannedId: String, userId: String): Boolean { + if(bannedId.length != userId.length) return false + + for(i: Int in 0..bannedId.length - 1) { + if(bannedId[i] != '*' && bannedId[i] != userId[i]) { + return false + } + } + + return true + } +} \ No newline at end of file diff --git "a/jung0115/\353\266\204\355\225\240\354\240\225\353\263\265/Programmers_60058.kt" "b/jung0115/\353\266\204\355\225\240\354\240\225\353\263\265/Programmers_60058.kt" index 492207d5..3269db1b 100644 --- "a/jung0115/\353\266\204\355\225\240\354\240\225\353\263\265/Programmers_60058.kt" +++ "b/jung0115/\353\266\204\355\225\240\354\240\225\353\263\265/Programmers_60058.kt" @@ -1,4 +1,4 @@ -// 프로그래머스 - 괄호 변환(Lv.2) +// 19차시 2024.10.16.수 : 프로그래머스 - 괄호 변환(Lv.2) class Solution { fun solution(p: String): String { // 괄호를 숫자로 변환 From 62bd63f794f14fa0a8373b170f8216829b5d63fe Mon Sep 17 00:00:00 2001 From: jung0115 Date: Sat, 19 Oct 2024 20:45:36 +0900 Subject: [PATCH 18/23] 2024-10-19 readme --- jung0115/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jung0115/README.md b/jung0115/README.md index 63add7b1..2a5707d4 100644 --- a/jung0115/README.md +++ b/jung0115/README.md @@ -21,4 +21,4 @@ | 17차시 | 2024.10.11.금 | 그리디 알고리즘 | [마법의 엘리베이터(Lv.2)](https://school.programmers.co.kr/learn/courses/30/lessons/148653) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/175 | | 18차시 | 2024.10.12.토 | 다이나믹 프로그래밍 | [뉴스 전하기(1135)](https://www.acmicpc.net/problem/1135) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/177 | | 19차시 | 2024.10.16.수 | 분할정복 | [괄호 변환(Lv.2)](https://school.programmers.co.kr/learn/courses/30/lessons/60058) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/178 | -| 20차시 | 2024.10.19.토 | 백트래킹 | [불량 사용자(Lv.3)](https://school.programmers.co.kr/learn/courses/30/lessons/64064) | | \ No newline at end of file +| 20차시 | 2024.10.19.토 | 백트래킹 | [불량 사용자(Lv.3)](https://school.programmers.co.kr/learn/courses/30/lessons/64064) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/180 | \ No newline at end of file From ae9bf881189e7311f368ba237f111c1fdcfaee73 Mon Sep 17 00:00:00 2001 From: jung0115 Date: Wed, 23 Oct 2024 14:28:46 +0900 Subject: [PATCH 19/23] 2024-10-23 --- jung0115/DFS/Programmers_43164.kt | 43 +++++++++++++++++++++++++++++++ jung0115/README.md | 3 ++- 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 jung0115/DFS/Programmers_43164.kt diff --git a/jung0115/DFS/Programmers_43164.kt b/jung0115/DFS/Programmers_43164.kt new file mode 100644 index 00000000..cb172f88 --- /dev/null +++ b/jung0115/DFS/Programmers_43164.kt @@ -0,0 +1,43 @@ +// 21차시 2024.10.23.수 : 프로그래머스 - 여행경로(Lv.2) +class Solution { + var N = 0 + + lateinit var used: Array + lateinit var cloneTickets: Array> + + lateinit var answer: Array + var answerStr: String = "" + + fun solution(tickets: Array>): Array { + val start = "ICN" + cloneTickets = tickets.clone() + + N = tickets.size + used = Array(N) { false } + + dfs(1, start, Array(N + 1) { start }) + + return answer + } + + fun dfs(idx: Int, resultStr: String, result: Array) { + if(idx == N + 1) { + if(answerStr.length == 0 || answerStr > resultStr) { + answerStr = resultStr + answer = result.clone() + } + return + } + + for(i: Int in 0..N-1) { + if(!used[i] && cloneTickets[i][0] == result[idx - 1]) { + used[i] = true + result[idx] = cloneTickets[i][1] + + dfs(idx + 1, resultStr + cloneTickets[i][1], result) + + used[i] = false + } + } + } +} \ No newline at end of file diff --git a/jung0115/README.md b/jung0115/README.md index 2a5707d4..edd77d96 100644 --- a/jung0115/README.md +++ b/jung0115/README.md @@ -21,4 +21,5 @@ | 17차시 | 2024.10.11.금 | 그리디 알고리즘 | [마법의 엘리베이터(Lv.2)](https://school.programmers.co.kr/learn/courses/30/lessons/148653) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/175 | | 18차시 | 2024.10.12.토 | 다이나믹 프로그래밍 | [뉴스 전하기(1135)](https://www.acmicpc.net/problem/1135) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/177 | | 19차시 | 2024.10.16.수 | 분할정복 | [괄호 변환(Lv.2)](https://school.programmers.co.kr/learn/courses/30/lessons/60058) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/178 | -| 20차시 | 2024.10.19.토 | 백트래킹 | [불량 사용자(Lv.3)](https://school.programmers.co.kr/learn/courses/30/lessons/64064) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/180 | \ No newline at end of file +| 20차시 | 2024.10.19.토 | 백트래킹 | [불량 사용자(Lv.3)](https://school.programmers.co.kr/learn/courses/30/lessons/64064) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/180 | +| 21차시 | 2024.10.23.수 | DFS | [여행경로(Lv.2)](https://school.programmers.co.kr/learn/courses/30/lessons/43164) | | \ No newline at end of file From cac6896769d871a7cf4c8b711a0e14b07fb1a00b Mon Sep 17 00:00:00 2001 From: jung0115 Date: Wed, 23 Oct 2024 14:29:33 +0900 Subject: [PATCH 20/23] 2024-10-23 readem --- jung0115/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jung0115/README.md b/jung0115/README.md index edd77d96..3d016d9f 100644 --- a/jung0115/README.md +++ b/jung0115/README.md @@ -22,4 +22,4 @@ | 18차시 | 2024.10.12.토 | 다이나믹 프로그래밍 | [뉴스 전하기(1135)](https://www.acmicpc.net/problem/1135) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/177 | | 19차시 | 2024.10.16.수 | 분할정복 | [괄호 변환(Lv.2)](https://school.programmers.co.kr/learn/courses/30/lessons/60058) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/178 | | 20차시 | 2024.10.19.토 | 백트래킹 | [불량 사용자(Lv.3)](https://school.programmers.co.kr/learn/courses/30/lessons/64064) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/180 | -| 21차시 | 2024.10.23.수 | DFS | [여행경로(Lv.2)](https://school.programmers.co.kr/learn/courses/30/lessons/43164) | | \ No newline at end of file +| 21차시 | 2024.10.23.수 | DFS | [여행경로(Lv.2)](https://school.programmers.co.kr/learn/courses/30/lessons/43164) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/181 | \ No newline at end of file From 48d8f26b7e96508f3dabcd29254a3646876ff3eb Mon Sep 17 00:00:00 2001 From: jung0115 Date: Wed, 30 Oct 2024 16:40:44 +0900 Subject: [PATCH 21/23] 2024-10-30 --- jung0115/README.md | 3 ++- .../Programmers_120107.kt" | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 "jung0115/\353\270\214\353\243\250\355\212\270\355\217\254\354\212\244/Programmers_120107.kt" diff --git a/jung0115/README.md b/jung0115/README.md index 3d016d9f..c7c54511 100644 --- a/jung0115/README.md +++ b/jung0115/README.md @@ -22,4 +22,5 @@ | 18차시 | 2024.10.12.토 | 다이나믹 프로그래밍 | [뉴스 전하기(1135)](https://www.acmicpc.net/problem/1135) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/177 | | 19차시 | 2024.10.16.수 | 분할정복 | [괄호 변환(Lv.2)](https://school.programmers.co.kr/learn/courses/30/lessons/60058) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/178 | | 20차시 | 2024.10.19.토 | 백트래킹 | [불량 사용자(Lv.3)](https://school.programmers.co.kr/learn/courses/30/lessons/64064) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/180 | -| 21차시 | 2024.10.23.수 | DFS | [여행경로(Lv.2)](https://school.programmers.co.kr/learn/courses/30/lessons/43164) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/181 | \ No newline at end of file +| 21차시 | 2024.10.23.수 | DFS | [여행경로(Lv.2)](https://school.programmers.co.kr/learn/courses/30/lessons/43164) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/181 | +| 22차시 | 2024.10.30.수 | 브루트포스 | [점 찍기(Lv.2)](https://school.programmers.co.kr/learn/courses/30/lessons/140107) | | \ No newline at end of file diff --git "a/jung0115/\353\270\214\353\243\250\355\212\270\355\217\254\354\212\244/Programmers_120107.kt" "b/jung0115/\353\270\214\353\243\250\355\212\270\355\217\254\354\212\244/Programmers_120107.kt" new file mode 100644 index 00000000..b5db0eac --- /dev/null +++ "b/jung0115/\353\270\214\353\243\250\355\212\270\355\217\254\354\212\244/Programmers_120107.kt" @@ -0,0 +1,14 @@ +// 22차시 2024.10.30.수 : 프로그래머스 - 점 찍기(Lv.2) +class Solution { + fun solution(k: Int, d: Int): Long { + var answer: Long = 0L + val dSquare: Long = d.toLong() * d.toLong() + + for (a in 0L..d.toLong() step(k.toLong())) { + val maxB: Long = Math.sqrt((dSquare - a * a).toDouble()).toLong() / k.toLong() + 1L + answer += maxB + } + + return answer + } +} \ No newline at end of file From f9fbd032935a0e34548831c99b5a7c5c49a3f5b0 Mon Sep 17 00:00:00 2001 From: jung0115 Date: Wed, 30 Oct 2024 16:42:09 +0900 Subject: [PATCH 22/23] 2024-10-30 readme --- jung0115/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jung0115/README.md b/jung0115/README.md index c7c54511..4be67319 100644 --- a/jung0115/README.md +++ b/jung0115/README.md @@ -23,4 +23,4 @@ | 19차시 | 2024.10.16.수 | 분할정복 | [괄호 변환(Lv.2)](https://school.programmers.co.kr/learn/courses/30/lessons/60058) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/178 | | 20차시 | 2024.10.19.토 | 백트래킹 | [불량 사용자(Lv.3)](https://school.programmers.co.kr/learn/courses/30/lessons/64064) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/180 | | 21차시 | 2024.10.23.수 | DFS | [여행경로(Lv.2)](https://school.programmers.co.kr/learn/courses/30/lessons/43164) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/181 | -| 22차시 | 2024.10.30.수 | 브루트포스 | [점 찍기(Lv.2)](https://school.programmers.co.kr/learn/courses/30/lessons/140107) | | \ No newline at end of file +| 22차시 | 2024.10.30.수 | 브루트포스 | [점 찍기(Lv.2)](https://school.programmers.co.kr/learn/courses/30/lessons/140107) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/182 | \ No newline at end of file From 937790bd27d417e35f4afbcfd245395ad1bfb10a Mon Sep 17 00:00:00 2001 From: jung0115 Date: Sat, 2 Nov 2024 15:15:17 +0900 Subject: [PATCH 23/23] 2024-11-04 --- jung0115/README.md | 3 ++- .../Programmers_42885.py" | 21 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 "jung0115/\352\267\270\353\246\254\353\224\224\354\225\214\352\263\240\353\246\254\354\246\230/Programmers_42885.py" diff --git a/jung0115/README.md b/jung0115/README.md index 4be67319..d023f182 100644 --- a/jung0115/README.md +++ b/jung0115/README.md @@ -23,4 +23,5 @@ | 19차시 | 2024.10.16.수 | 분할정복 | [괄호 변환(Lv.2)](https://school.programmers.co.kr/learn/courses/30/lessons/60058) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/178 | | 20차시 | 2024.10.19.토 | 백트래킹 | [불량 사용자(Lv.3)](https://school.programmers.co.kr/learn/courses/30/lessons/64064) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/180 | | 21차시 | 2024.10.23.수 | DFS | [여행경로(Lv.2)](https://school.programmers.co.kr/learn/courses/30/lessons/43164) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/181 | -| 22차시 | 2024.10.30.수 | 브루트포스 | [점 찍기(Lv.2)](https://school.programmers.co.kr/learn/courses/30/lessons/140107) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/182 | \ No newline at end of file +| 22차시 | 2024.10.30.수 | 브루트포스 | [점 찍기(Lv.2)](https://school.programmers.co.kr/learn/courses/30/lessons/140107) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/182 | +| 23차시 | 2024.11.02.토 | 그리디 알고리즘 | [구명보트(Lv.2)](https://school.programmers.co.kr/learn/courses/30/lessons/42885) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/184 | \ No newline at end of file diff --git "a/jung0115/\352\267\270\353\246\254\353\224\224\354\225\214\352\263\240\353\246\254\354\246\230/Programmers_42885.py" "b/jung0115/\352\267\270\353\246\254\353\224\224\354\225\214\352\263\240\353\246\254\354\246\230/Programmers_42885.py" new file mode 100644 index 00000000..a6b54b60 --- /dev/null +++ "b/jung0115/\352\267\270\353\246\254\353\224\224\354\225\214\352\263\240\353\246\254\354\246\230/Programmers_42885.py" @@ -0,0 +1,21 @@ +# 23차시 2024.11.02.토 : 프로그래머스 - 구명보트(Lv.2) +from collections import deque + +def solution(people, limit): + answer = 0 + people.sort(reverse = True) + queue = deque(people) + + while len(queue) > 1 : + if queue[0] + queue[-1] <= limit : + queue.pop() + queue.popleft() + answer += 1 + else : + queue.popleft() + answer += 1 + + if len(queue) > 0 : + answer += 1 + + return answer \ No newline at end of file