-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
23-jung0115 #184
Merged
Merged
23-jung0115 #184
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
f8ed7ae
2024-09-23
jung0115 9acd0df
2024-09-23 readme
jung0115 2a2871b
2024-09-23 update:
jung0115 9078966
2024-09-26
jung0115 b2f729f
2024-09-26 readme
jung0115 3205c13
2024-09-28
jung0115 84d1ad0
2024-09-28 readme
jung0115 8bec559
2024-10-05
jung0115 15f88a1
2024-10-05
jung0115 fec78c0
2024-10-05 readme
jung0115 a3699d1
2024-10-11
jung0115 3749b82
2024-10-11 readme
jung0115 5a6f8ae
2024-10-12
jung0115 5f9a779
2024-10-12 readme
jung0115 f197b27
2024-10-16
jung0115 9656a93
2024-10-16 readme
jung0115 f5242d3
2024-10-19
jung0115 62bd63f
2024-10-19 readme
jung0115 ae9bf88
2024-10-23
jung0115 cac6896
2024-10-23 readem
jung0115 48d8f26
2024-10-30
jung0115 f9fbd03
2024-10-30 readme
jung0115 937790b
2024-11-04
jung0115 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
*.jars | ||
*.jar | ||
*.jar | ||
*.class |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// 21차시 2024.10.23.수 : 프로그래머스 - 여행경로(Lv.2) | ||
class Solution { | ||
var N = 0 | ||
|
||
lateinit var used: Array<Boolean> | ||
lateinit var cloneTickets: Array<Array<String>> | ||
|
||
lateinit var answer: Array<String> | ||
var answerStr: String = "" | ||
|
||
fun solution(tickets: Array<Array<String>>): Array<String> { | ||
val start = "ICN" | ||
cloneTickets = tickets.clone() | ||
|
||
N = tickets.size | ||
used = Array<Boolean>(N) { false } | ||
|
||
dfs(1, start, Array<String>(N + 1) { start }) | ||
|
||
return answer | ||
} | ||
|
||
fun dfs(idx: Int, resultStr: String, result: Array<String>) { | ||
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 | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<CupNoodle> { | ||
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<Integer> 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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Integer, Integer> cupNoodles = new HashMap<Integer, Integer>(); | ||
|
||
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<Integer> keys = cupNoodles.keySet().iterator(); | ||
while(keys.hasNext()){ | ||
int key = keys.next(); | ||
answer += cupNoodles.get(key); | ||
} | ||
|
||
System.out.print(answer); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<MutableList<Int>> | ||
lateinit var dp: Array<Int> | ||
|
||
fun main() { | ||
val br = BufferedReader(InputStreamReader(System.`in`)) | ||
|
||
var N = br.readLine().toInt() // 직원의 수 | ||
|
||
val st = StringTokenizer(br.readLine()) | ||
employees = Array(N) { mutableListOf<Int>() } | ||
dp = Array<Int>(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] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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][M] < 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); | ||
|
||
} | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// 20차시 2024.10.19.토 : 프로그래머스 - 불량 사용자(Lv.3) | ||
import java.util.HashSet | ||
|
||
class Solution { | ||
lateinit var userIdsClone: Array<String> | ||
lateinit var bannedIdsClone: Array<String> | ||
lateinit var collectIds: Array<MutableList<String>> | ||
|
||
val answer = HashSet<HashSet<String>>() | ||
|
||
fun solution(user_id: Array<String>, banned_id: Array<String>): Int { | ||
userIdsClone = user_id.clone() | ||
bannedIdsClone = banned_id.clone() | ||
|
||
collectIds = Array(banned_id.size) { mutableListOf<String>() } | ||
|
||
// 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<String>(), 0) | ||
|
||
return answer.size | ||
} | ||
|
||
fun dfs(set: HashSet<String>, 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 | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이렇게 queue가 비어있을 때까지 반복하는 구조로도 작성할 수 있습니다🙂