Skip to content
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

[소병희] - 민겸 수, 이모티콘 할인행사, 영상처리 #207

Merged
merged 4 commits into from
Feb 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions src/main/kotlin/byeonghee/week51/민겸 수.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package byeonghee.week51

class 소병희_민겸수 {
companion object {
fun solve() {
fun solve() = with(System.`in`.bufferedReader()) {
var cntM = 0
val sbMax = StringBuilder()
val sbMin = StringBuilder()
Comment on lines +8 to +9
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

두 변수를 기준으로 전체적으로 코드가 깔끔했어요!👍


readLine().forEach { c ->
when(c) {
'M' -> {
cntM++
}
'K' -> {
sbMax.append(5)

if (cntM-- > 0) {
sbMax.append(0)
sbMin.append(1)
}

repeat(cntM) {
sbMax.append(0)
sbMin.append(0)
}

sbMin.append(5)

cntM = 0
}
}
}

if (cntM-- > 0) {
sbMax.append(1)
sbMin.append(1)
}

repeat(cntM) {
sbMax.append(1)
sbMin.append(0)
}

println(sbMax)
println(sbMin)
}
}
}
}

fun main() {
소병희_민겸수.solve()
}
24 changes: 24 additions & 0 deletions src/main/kotlin/byeonghee/week51/소가 길을 건너간 이유.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package byeonghee.week51

class 소병희_소가길을건너간이유 {
companion object {
fun solve() = with(System.`in`.bufferedReader()) {
val n = readLine().toInt()
val cows = IntArray(11) { -1 }
var ans = 0

repeat(n) {
val (num, pos) = readLine().split(" ").map { it.toInt() }

if (cows[num] != -1 && cows[num] != pos) ans++
cows[num] = pos
}

println(ans)
}
}
}

fun main() {
소병희_소가길을건너간이유.solve()
}
68 changes: 68 additions & 0 deletions src/main/kotlin/byeonghee/week51/영상처리.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package byeonghee.week51

class 소병희_영상처리 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3문제 푼 병희님 멋져요

companion object {
val dr = intArrayOf(-1, 0, 1, 0)
val dc = intArrayOf(0, 1, 0, -1)

fun solve() = with(System.`in`.bufferedReader()) {
val (n, m) = readLine().split(" ").map { it.toInt() }
val screen = Array(n) { IntArray(m) }
val visited = Array(n) { BooleanArray(m) }
var stuff = 0

repeat(n) { i ->
val line = readLine().split(" ").map { it.toInt() }
repeat(m) { j ->
screen[i][j] = (line[j*3] + line[j*3 + 1] + line[j*3 + 2]) / 3
}
}

val t = readLine().toInt()

for(i in 0 until n) for(j in 0 until m) {
screen[i][j] = if (screen[i][j] >= t) 255 else 0
}

fun bfs(i: Int, j: Int) {
val q = ArrayDeque<IntArray>()
q.add(intArrayOf(i, j))
screen[i][j] = stuff

while(q.isNotEmpty()) {
val (r, c) = q.removeFirst()

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 m) continue

if (visited[nr][nc]) continue
visited[nr][nc] = true

if(screen[nr][nc] == 255) {
screen[nr][nc] = stuff
q.add(intArrayOf(nr, nc))
}
}
}
}

for(i in 0 until n) for(j in 0 until m) {
if (visited[i][j]) continue
visited[i][j] = true

if (screen[i][j] == 255) {
stuff++
bfs(i, j)
}
}

println(stuff)
}
}
}

fun main() {
소병희_영상처리.solve()
}
58 changes: 58 additions & 0 deletions src/main/kotlin/byeonghee/week51/이모티콘 할인행사.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package byeonghee.week51

class 소병희_이모티콘할인행사 {

val answer = IntArray(2)
val discounts = 10..40 step 10
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오 코드가 이뻐요


lateinit var users: Array<IntArray>
lateinit var emoticons: IntArray

fun solution(_users: Array<IntArray>, _emoticons: IntArray): IntArray {
users = _users
emoticons = _emoticons

recursiveDiscount(0, IntArray(users.size))

return answer
}

fun recursiveDiscount(idx: Int, shopped: IntArray) {
if (idx == emoticons.size) {
var plus = 0
var gain = 0

for(bill in shopped) {
if (bill == -1) plus++
else gain += bill
}
Comment on lines +25 to +28
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shopped 를 아래에서 처리 해준게 보기 좋았어요!🙂


if (answer[0] < plus) {
answer[0] = plus
answer[1] = gain
}
else if (answer[0] == plus && answer[1] < gain) {
answer[1] = gain
}
return
}

for(discount in discounts) {
var newPrice = emoticons[idx] / 100 * (100 - discount)
val newShopped = shopped.clone()

for((user, data) in users.withIndex()) {
val (ratio, budget) = data
if (shopped[user] == -1) continue
if (discount >= ratio) {
newShopped[user] += newPrice
if (newShopped[user] >= budget) {
newShopped[user] = -1
}
}
}

recursiveDiscount(idx + 1, newShopped)
}
}
}