-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #257 from wellFoundedDevelopers/byeonghee/62week
[소병희] - 최소 스패닝 트리, 카드 섞기, 경쟁적 전염, Coins
- Loading branch information
Showing
4 changed files
with
178 additions
and
0 deletions.
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 |
---|---|---|
@@ -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() | ||
} |
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,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 | ||
|
||
tube[nr][nc] = tube[r][c] | ||
time[nr][nc] = time[r][c] + 1 | ||
q.add(intArrayOf(nr, nc)) | ||
} | ||
} | ||
|
||
println(tube[x-1][y-1]) | ||
} | ||
} | ||
} | ||
|
||
fun main() { | ||
`소병희_경쟁적 전염`.solve() | ||
} |
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,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 | ||
} | ||
|
||
answer += w | ||
} | ||
|
||
println(answer) | ||
} | ||
} | ||
} | ||
|
||
fun main() { | ||
소병희_최소스패닝트리.solve() | ||
} |
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,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) { | ||
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() | ||
} |