-
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
[소병희] - 작업, 키 순서, 구간 합 구하기 5, 도넛과 막대 그래프 #218
Changes from 3 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.week53 | ||
|
||
class 소병희_구간합구하기5 { | ||
companion object { | ||
fun solve() = with(System.`in`.bufferedReader()) { | ||
val (n, m) = readLine().split(" ").map { it.toInt() } | ||
val table = Array(n + 1) { IntArray(n + 1) } | ||
val sb = StringBuilder() | ||
|
||
repeat(n) { i -> | ||
readLine().split(" ").forEachIndexed { j, v -> | ||
table[i+1][j+1] = table[i+1][j] + v.toInt() | ||
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. 입력 받으면서 처리하는게 깔끔하니 예쁘네요 |
||
} | ||
} | ||
|
||
repeat(n) { i -> | ||
repeat(n) { j -> | ||
table[i+1][j+1] += table[i][j+1] | ||
} | ||
} | ||
Comment on lines
+10
to
+20
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. 이렇게 쉽게 구간합을 구할 수 있었네요..😎 |
||
|
||
repeat(m) { | ||
val (r1, c1, r2, c2) = readLine().split(" ").map { it.toInt() } | ||
sb.appendLine(table[r2][c2] + table[r1-1][c1-1] - table[r1-1][c2] - table[r2][c1-1]) | ||
} | ||
|
||
println(sb) | ||
} | ||
} | ||
} | ||
|
||
fun main() { | ||
소병희_구간합구하기5.solve() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package byeonghee.week53 | ||
|
||
class 소병희_작업 { | ||
companion object { | ||
fun solve() = with(System.`in`.bufferedReader()) { | ||
val (n, m) = readLine().split(" ").map { it.toInt() } | ||
val preJob = Array(n + 1) { ArrayDeque<Int>() } | ||
|
||
repeat(m) { | ||
val (pre, cur) = readLine().split(" ").map { it.toInt() } | ||
preJob[cur].add(pre) | ||
} | ||
|
||
val x = readLine().toInt() | ||
var answer = 0 | ||
val visited = BooleanArray(n+1) | ||
val q = ArrayDeque<Int>(x) | ||
q.add(x) | ||
visited[x] = true | ||
|
||
while(q.isNotEmpty()) { | ||
val cur = q.removeFirst() | ||
preJob[cur].forEach { | ||
if (visited[it].not()) { | ||
q.add(it) | ||
visited[it] = true | ||
answer++ | ||
} | ||
} | ||
} | ||
|
||
println(answer) | ||
} | ||
} | ||
} | ||
|
||
fun main() { | ||
소병희_작업.solve() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package byeonghee.week53 | ||
|
||
class 소병희_키순서 { | ||
companion object { | ||
fun solve() = with(System.`in`.bufferedReader()) { | ||
val (n, m) = readLine().split(" ").map { it.toInt() } | ||
val adj = Array(n) { IntArray(n) } | ||
|
||
repeat(m) { | ||
val (low, high) = readLine().split(" ").map { it.toInt() - 1 } | ||
adj[low][high] = 1 | ||
adj[high][low] = -1 | ||
} | ||
|
||
for(mid in 0 until n) for(a in 0 until n) for(b in 0 until n) { | ||
val compare = adj[a][mid] + adj[mid][b] | ||
when (compare) { | ||
2 -> { | ||
adj[a][b] = 1 | ||
adj[b][a] = -1 | ||
} | ||
|
||
-2 -> { | ||
adj[a][b] = -1 | ||
adj[b][a] = 1 | ||
} | ||
Comment on lines
+18
to
+26
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. 오 방법이 되게 신기해요 |
||
} | ||
} | ||
|
||
var answer = 0 | ||
for(a in 0 until n) { | ||
var cnt = 1 | ||
for(b in 0 until n) { | ||
if (adj[a][b] != 0) cnt++ | ||
} | ||
Comment on lines
+33
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. 앞뒤를 모두 체크하셔서 이 부분에서 저랑 차이가 있네요! |
||
if (cnt == n) answer++ | ||
} | ||
|
||
println(answer) | ||
} | ||
} | ||
} | ||
|
||
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.
일부로 사이즈 하나씩 늘려서 푸는 게 👍