-
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, 도넛과 막대 그래프 #219
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,54 @@ | ||
package heejik.`53week` | ||
|
||
class `구간 합 구하기 5` { | ||
|
||
private var n: Int = 0 | ||
private var m: Int = 0 | ||
private val board = mutableListOf<MutableList<Int>>() | ||
private val poses = mutableListOf<List<Int>>() | ||
fun solve() { | ||
input() | ||
changeBoard() | ||
poses.forEach { | ||
getPrefixSum(it[0] - 1, it[1] - 1, it[2] - 1, it[3] - 1).also { answer -> | ||
println(answer) | ||
} | ||
} | ||
} | ||
|
||
private fun input() { | ||
readln().split(' ').map { it.toInt() }.also { | ||
n = it.first() | ||
m = it.last() | ||
} | ||
repeat(n) { | ||
board.add(readln().split(' ').map { it.toInt() }.toMutableList()) | ||
} | ||
repeat(m) { | ||
poses.add(readln().split(' ').map { it.toInt() }) | ||
} | ||
} | ||
|
||
private fun changeBoard() { | ||
for (x in 0 until n) { | ||
for (y in 0 until n) { | ||
val minusX = if (x == 0) -1 else x - 1 | ||
val minusY = if (y == 0) -1 else y - 1 | ||
board[x][y] += (if (minusY != -1) board[x][minusY] else 0) + | ||
(if (minusX != -1) board[minusX][y] else 0) - | ||
(if (minusX != -1 && minusY != -1) board[minusX][minusY] else 0) | ||
} | ||
} | ||
} | ||
|
||
private fun getPrefixSum(x1: Int, y1: Int, x2: Int, y2: Int): Int { | ||
val leftSum = if (y1 == 0) 0 else board[x2][y1 - 1] | ||
val upSum = if (x1 == 0) 0 else board[x1 - 1][y2] | ||
val diagonalSum = if (x1 == 0 || y1 == 0) 0 else board[x1 - 1][y1 - 1] | ||
return board[x2][y2] - leftSum - upSum + diagonalSum | ||
} | ||
} | ||
|
||
fun main() { | ||
`구간 합 구하기 5`().solve() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package heejik.`53week` | ||
|
||
import kotlin.math.max | ||
|
||
class 서강그라운드 { | ||
|
||
fun solve() { | ||
val (n, m, r) = readln().split(' ').map { it.toInt() } | ||
val itemCounts = readln().split(' ').map { it.toInt() }.toMutableList() | ||
itemCounts.add(0, 0) | ||
val distances = List(size = n + 1) { MutableList(size = n + 1) { 16 } } | ||
var answer = 0 | ||
|
||
repeat(r) { | ||
val (a, b, distance) = readln().split(' ').map { it.toInt() } | ||
distances[a][b] = distance | ||
distances[b][a] = distance | ||
} | ||
|
||
for (k in 1..n) { | ||
for (i in 1..n) { | ||
for (j in 1..n) { | ||
if (distances[i][j] > distances[i][k] + distances[k][j]) { | ||
distances[i][j] = distances[i][k] + distances[k][j] | ||
} | ||
} | ||
} | ||
} | ||
|
||
for (region in 1..n) { | ||
var sum = itemCounts[region] | ||
for (other in 1..n) { | ||
if (region == other) continue | ||
if (distances[region][other] <= m) sum += itemCounts[other] | ||
} | ||
answer = max(answer, sum) | ||
} | ||
|
||
println(answer) | ||
} | ||
} | ||
|
||
|
||
fun main() { | ||
서강그라운드().solve() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package heejik.`53week` | ||
|
||
class 작업 { | ||
|
||
private var n = 0 | ||
private var m = 0 | ||
private var findNum = 0 | ||
private var answer = 0 | ||
|
||
// 내부엔 나를 쏘는 애들 | ||
private lateinit var relation: List<MutableList<Int>> | ||
|
||
fun solve() { | ||
input() | ||
bfs() | ||
println(answer) | ||
} | ||
|
||
private fun input() { | ||
readln().split(' ').map { it.toInt() }.also { | ||
n = it[0] | ||
m = it[1] | ||
} | ||
relation = List(size = n + 1) { emptyList<Int>().toMutableList() } | ||
repeat(m) { | ||
val (shot, receive) = readln().split(' ').map { it.toInt() } | ||
relation[receive].add(shot) | ||
} | ||
findNum = readln().toInt() | ||
} | ||
|
||
private fun bfs() { | ||
val deque = ArrayDeque<Int>() | ||
val visited = BooleanArray(size = n + 1) | ||
deque.add(findNum) | ||
visited[findNum] = true | ||
|
||
while (deque.isNotEmpty()) { | ||
val standard = deque.removeFirst() | ||
relation[standard].forEach { | ||
if (visited[it]) return@forEach | ||
deque.add(it) | ||
visited[it] = true | ||
answer++ | ||
} | ||
} | ||
} | ||
} | ||
|
||
fun main() { | ||
작업().solve() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package heejik.`53week` | ||
|
||
import java.io.BufferedReader | ||
import java.io.InputStreamReader | ||
|
||
class `키 순서` { | ||
|
||
private var n = 0 | ||
private var m = 0 | ||
private lateinit var relation: List<BooleanArray> | ||
|
||
val br = BufferedReader(InputStreamReader(System.`in`)) | ||
|
||
fun solve() { | ||
input() | ||
createRelation() | ||
getAnswer().also { answer -> | ||
println(answer) | ||
} | ||
} | ||
|
||
private fun input() { | ||
br.readLine().split(' ').map { it.toInt() }.run { | ||
n = this[0] | ||
m = this[1] | ||
} | ||
relation = List(size = n + 1) { BooleanArray(size = n + 1) } | ||
|
||
repeat(m) { | ||
val (small, large) = br.readLine().split(' ').map { it.toInt() } | ||
relation[small][large] = true | ||
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. 한 방향으로만 해도 되는군요,,,,,, |
||
} | ||
} | ||
|
||
private fun createRelation() { | ||
for (k in 1..n) { | ||
for (i in 1..n) { | ||
for (j in 1..n) { | ||
if (relation[i][k] && relation[k][j]) | ||
relation[i][j] = true | ||
} | ||
} | ||
} | ||
} | ||
Comment on lines
+35
to
+44
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
+35
to
+44
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. 플로이드 워셜로 구할 수도 있군요,,,! |
||
|
||
private fun getAnswer(): Int { | ||
var answer = 0 | ||
for (i in 1..n) { | ||
var count = 0 | ||
for (j in 1..n) { | ||
if (relation[i][j] || relation[j][i]) count++ | ||
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 (count == n - 1) answer++ | ||
} | ||
|
||
return 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.
오 그래도 변수명을 잘지으셔서 이해가 잘 됩니다!