-
Notifications
You must be signed in to change notification settings - Fork 0
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
[소병희] - 최소 스패닝 트리, 카드 섞기, 경쟁적 전염, Coins #257
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,35 @@ | ||
package byeonghee.week62 | ||
|
||
class 소병희_Coins { | ||
companion object { | ||
fun solve() = with(System.`in`.bufferedReader()) { | ||
val t = readLine().toInt() | ||
val sb = StringBuilder() | ||
|
||
repeat(t) { | ||
val n = readLine().toInt() | ||
val coins = IntArray(n) | ||
|
||
readLine().split(" ").forEachIndexed { i, v -> coins[i] = v.toInt() } | ||
|
||
val m = readLine().toInt() | ||
val dp = IntArray(m+1) | ||
|
||
dp[0] = 1 | ||
for(coin in coins) { | ||
for(price in coin .. m) { | ||
dp[price] += dp[price - coin] | ||
} | ||
} | ||
|
||
sb.appendLine(dp[m]) | ||
} | ||
|
||
println(sb) | ||
} | ||
} | ||
} | ||
|
||
fun main() { | ||
소병희_Coins.solve() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package byeonghee.week62 | ||
|
||
class `소병희_경쟁적 전염` { | ||
companion object { | ||
val dr = intArrayOf(-1, 0, 1, 0) | ||
val dc = intArrayOf(0, 1, 0, -1) | ||
|
||
fun solve() = with(System.`in`.bufferedReader()) { | ||
val (n, k) = readLine().split(" ").map { it.toInt() } | ||
val tube = Array(n) { IntArray(n) } | ||
val time = Array(n) { IntArray(n) } | ||
val q = ArrayDeque<IntArray>(n * n) | ||
|
||
for(i in 0 until n) { | ||
readLine().split(" ").forEachIndexed { j, v -> | ||
tube[i][j] = v.toInt() | ||
if (tube[i][j] > 0) q.add(intArrayOf(i, j, tube[i][j], 0)) | ||
} | ||
} | ||
|
||
val (s, x, y) = readLine().split(" ").map { it.toInt() } | ||
|
||
while(q.isNotEmpty()) { | ||
val (r, c) = q.removeFirst() | ||
if (time[r][c] == s) continue | ||
|
||
for(d in 0 until 4) { | ||
val nr = r + dr[d] | ||
val nc = c + dc[d] | ||
if (nr !in 0 until n || nc !in 0 until n) continue | ||
if (tube[nr][nc] in 1 until tube[r][c]) continue | ||
if (tube[nr][nc] > 0 && time[nr][nc] <= time[r][c]) 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. 순간 헷갈렸는데 time[nr][nc]를 갱신하기 전이라 이 비교가 맞네요 허허
Comment on lines
+31
to
+32
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. 아 이 친구들이 번호의 우선순위와 이전 영역의 침범을 막는 코드군요!👍 |
||
|
||
tube[nr][nc] = tube[r][c] | ||
time[nr][nc] = time[r][c] + 1 | ||
Comment on lines
+34
to
+35
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. time을 이용해서 순서를 정하는게 좋아보였습니다! |
||
q.add(intArrayOf(nr, nc)) | ||
} | ||
} | ||
|
||
println(tube[x-1][y-1]) | ||
} | ||
} | ||
} | ||
|
||
fun main() { | ||
`소병희_경쟁적 전염`.solve() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package byeonghee.week62 | ||
|
||
import java.util.PriorityQueue | ||
|
||
class 소병희_최소스패닝트리 { | ||
companion object { | ||
fun solve() = with(System.`in`.bufferedReader()) { | ||
val (v, e) = readLine().split(" ").map { it.toInt() } | ||
val visited = IntArray(v+1) { it } | ||
val pq = PriorityQueue<IntArray> { a, b -> a[2] - b[2] } | ||
var answer = 0 | ||
|
||
repeat(e) { | ||
pq.add(readLine().split(" ").map { it.toInt() }.toIntArray()) | ||
} | ||
|
||
while(pq.isNotEmpty()) { | ||
val (a, b, w) = pq.poll() | ||
|
||
var parA = a | ||
var parB = b | ||
|
||
while(visited[parA] != parA) { | ||
parA = visited[parA] | ||
} | ||
while(visited[parB] != parB) { | ||
parB = visited[parB] | ||
} | ||
|
||
if (parA == parB) continue | ||
|
||
if (parA < parB) { | ||
visited[parB] = parA | ||
} | ||
else { | ||
visited[parA] = parB | ||
} | ||
Comment on lines
+17
to
+37
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. 반례 제공도 감사드리고 병희님 코드 참고하면서 문제도 풀었습니다!!👍 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. 맞아유 반례 덕분에 저도 이해됐어요!!!
Comment on lines
+20
to
+37
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. 오오.. 요런식으로도,,, |
||
|
||
answer += w | ||
} | ||
|
||
println(answer) | ||
} | ||
} | ||
} | ||
|
||
fun main() { | ||
소병희_최소스패닝트리.solve() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package byeonghee.week62 | ||
|
||
class 소병희_카드섞기 { | ||
companion object { | ||
fun solve() = with(System.`in`.bufferedReader()) { | ||
val n = readLine().toInt() | ||
val owner = IntArray(n) { it % 3 } | ||
var card = IntArray(n) { it } | ||
|
||
val cardGoal = IntArray(n) | ||
val shuffle = IntArray(n) | ||
|
||
readLine().split(" ").forEachIndexed { i, v -> | ||
cardGoal[i] = v.toInt() | ||
} | ||
|
||
readLine().split(" ").forEachIndexed { i, v -> | ||
shuffle[i] = v.toInt() | ||
} | ||
|
||
for(i in 0 .. 1_000_000) { | ||
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. 참신했습니다. 역시 병희님 |
||
var cnt = 0 | ||
|
||
for(c in 0 until n) { | ||
if (owner[c] == cardGoal[card[c]]) cnt++ | ||
} | ||
|
||
if (cnt == n) { | ||
println(i) | ||
return@with | ||
} | ||
|
||
val newCard = IntArray(n) | ||
for(c in 0 until n) { | ||
newCard[shuffle[c]] = card[c] | ||
} | ||
card = newCard | ||
} | ||
|
||
println(-1) | ||
} | ||
} | ||
} | ||
|
||
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.
다들 1차원으로 깔끔하게 하시는군요