-
Notifications
You must be signed in to change notification settings - Fork 0
[소병희] - 동전, 호텔, 멀쩡한 사각형, 택배 배송 #247
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package byeonghee.week59 | ||
|
||
class 소병희_동전 { | ||
companion object { | ||
fun solve() = with(System.`in`.bufferedReader()) { | ||
val t = readLine().toInt() | ||
repeat(t) { | ||
val n = readLine().toInt() | ||
val coins = IntArray(n) | ||
|
||
readLine().split(" ").forEachIndexed { i, v -> coins[i] = v.toInt() } | ||
|
||
val price = readLine().toInt() | ||
val dp = Array(price + 1) { IntArray(n) } | ||
|
||
repeat(n) { i -> if (price >= coins[i]) dp[coins[i]][i] = 1 } | ||
for(p in 1 .. price) { | ||
for((i, c) in coins.withIndex()) { | ||
if (p < c) continue | ||
for(pre in 0 .. i) { | ||
dp[p][i] += dp[p - c][pre] | ||
} | ||
} | ||
} | ||
|
||
println(dp[price].sumOf { it }) | ||
} | ||
} | ||
} | ||
} | ||
|
||
fun main() { | ||
소병희_동전.solve() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package byeonghee.week59 | ||
|
||
class 소병희_멀쩡한사각형 { | ||
fun solution(w: Int, h: Int): Long { | ||
val gcd = gcd(w, h) | ||
val sw = w / gcd | ||
val sh = h / gcd | ||
val adj = 1 + (sw - 1) + (sh - 1) | ||
|
||
return (0L + w) * h - gcd * adj | ||
} | ||
Comment on lines
+4
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "가로지는 선" 풀이 잘 들었습니다!😀 |
||
} | ||
|
||
fun gcd(_a: Int, _b: Int): Int { | ||
var a = _a | ||
var b = _b | ||
|
||
while(b > 0) { | ||
a = b.also { b = a % b } | ||
} | ||
|
||
return a | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package byeonghee.week59 | ||
|
||
import java.util.* | ||
|
||
class 소병희_택배배송 { | ||
companion object { | ||
data class Node(val i: Int, val v: Int) | ||
Comment on lines
+5
to
+7
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 틀렸던 부분 말씀 주셔서 좋았어요! |
||
|
||
fun solve() = with(System.`in`.bufferedReader()) { | ||
val (n, m) = readLine().split(" ").map { it.toInt() } | ||
val dist = IntArray(n) { m * 1000 } | ||
val edges = Array(n) { ArrayList<Node>() } | ||
val pq = PriorityQueue<Node>(m + 2) { a, b -> (a.v- b.v) } | ||
|
||
var a = 0 | ||
var b = 0 | ||
var c = 0 | ||
repeat(m) { | ||
readLine().split(" ").let { | ||
a = it[0].toInt() - 1 | ||
b = it[1].toInt() - 1 | ||
c = it[2].toInt() | ||
edges[a].add(Node(b, c)) | ||
edges[b].add(Node(a, c)) | ||
} | ||
} | ||
|
||
pq.add(Node(0, 0)) | ||
while(pq.isNotEmpty()) { | ||
val (i, v) = pq.poll() | ||
if (dist[i] <= v) continue | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 오 이거 하면 좀 더 빠르겠네요! |
||
|
||
dist[i] = v | ||
edges[i].forEach { x -> | ||
if (dist[x.i] > v + x.v) | ||
pq.add(Node(x.i, x.v + v)) | ||
} | ||
} | ||
|
||
println(dist[n-1]) | ||
} | ||
|
||
} | ||
} | ||
|
||
fun main() { | ||
소병희_택배배송.solve() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package byeonghee.week59 | ||
|
||
class 소병희_호텔 { | ||
companion object { | ||
fun solve() = with(System.`in`.bufferedReader()) { | ||
val (c, n) = readLine().split(" ").map { it.toInt() } | ||
val cities = Array(n) { IntArray(2) } | ||
val dp = IntArray(c * 100 + 1) | ||
|
||
repeat(n) { i -> | ||
val (cost, people) = readLine().split(" ").map { it.toInt() } | ||
cities[i][0] = cost | ||
cities[i][1] = people | ||
} | ||
|
||
for((cost, people) in cities) { | ||
for(price in 1 .. c * 100) { | ||
if (price - cost >= 0) { | ||
dp[price] = dp[price] | ||
.coerceAtLeast(dp[price - cost] + people) | ||
} | ||
} | ||
} | ||
|
||
for(i in 1 .. c * 100) { | ||
if (dp[i] >= c) { | ||
println(i) | ||
return@with | ||
} | ||
} | ||
Comment on lines
+25
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 그냥 print(dp[c])하면 안되나요?! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 인덱스가 인원수가 아니라 가격이라서 이렇게 해줘야 했어요 흑흑 |
||
} | ||
} | ||
} | ||
|
||
fun main() { | ||
소병희_호텔.solve() | ||
} |
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.
설명 주셔서 감사했습니다! 출력하면서 다시금 파악해야겠어요!🫡