Skip to content

Commit

Permalink
Merge pull request #207 from wellFoundedDevelopers/byeonghee/51week
Browse files Browse the repository at this point in the history
[소병희] - 민겸 수, 이모티콘 할인행사, 영상처리
  • Loading branch information
bngsh authored Feb 25, 2024
2 parents dab07e0 + 45d507d commit 9487b4a
Show file tree
Hide file tree
Showing 4 changed files with 205 additions and 0 deletions.
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()

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 소병희_영상처리 {
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

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
}

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)
}
}
}

0 comments on commit 9487b4a

Please sign in to comment.