Skip to content

Commit

Permalink
Merge pull request #277 from wellFoundedDevelopers/heejik/66week
Browse files Browse the repository at this point in the history
[장희직] - 용액, 순회강연, 혼자서 하는 틱택톡, 맥주 마시면서 걸어다니기
  • Loading branch information
jhg3410 authored Jun 9, 2024
2 parents dfee5d1 + b501b0e commit 00a4495
Show file tree
Hide file tree
Showing 4 changed files with 172 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/main/kotlin/heejik/66week/맥주 마시면서 걸어가기.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from collections import deque


def get_diff(pos1, pos2):
return abs(pos1[0] - pos2[0]) + abs(pos1[1] - pos2[1])


def solve():
can_go = False
store_pos = []
n = int(input())
visited_store_idx = [False] * (n + 1)
start_pos = list(map(int, input().split()))
for _ in range(n):
pos = list(map(int, input().split()))
store_pos.append(pos)
end_pos = list(map(int, input().split()))
store_pos.append(end_pos)

queue = deque()
queue.append(start_pos)

while queue:
s_pos = queue.popleft()
if s_pos == end_pos:
can_go = True
break
for (idx, store) in enumerate(store_pos):
if visited_store_idx[idx]: continue
diff = get_diff(s_pos, store)
if diff > 1000: continue

queue.append(store)
visited_store_idx[idx] = True

print("happy" if can_go else "sad")


if __name__ == '__main__':
t = int(input())
for _ in range(t):
solve()
44 changes: 44 additions & 0 deletions src/main/kotlin/heejik/66week/순회강연.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package heejik.`66week`

import java.util.PriorityQueue

private class 순회강연 {

data class Lecture(
val fee: Int,
val deadline: Int
)

fun solve() {
val n = readln().toInt()
val lectures = mutableListOf<Lecture>()
val storeLectures = PriorityQueue<Lecture> { l1, l2 ->
l1.fee - l2.fee
}

repeat(n) {
val lecture = readln().split(' ').map { it.toInt() }.run {
Lecture(fee = this[0], deadline = this[1])
}
lectures.add(lecture)
}

lectures.sortedBy { it.deadline }.forEach { lecture ->
if (lecture.deadline > storeLectures.size) {
storeLectures.add(lecture)
} else {
val smallFeeLecture = storeLectures.peek()
if (lecture.fee > smallFeeLecture.fee) {
storeLectures.poll()
storeLectures.add(lecture)
}
}
}

println(storeLectures.sumOf { it.fee })
}
}

fun main() {
순회강연().solve()
}
39 changes: 39 additions & 0 deletions src/main/kotlin/heejik/66week/용액.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package heejik.`66week`

import kotlin.math.absoluteValue

private class 용액 {

fun solve() {
val n = readln().toInt()
val numbers = readln().split(' ').map { it.toInt() }

var start = 0
var end = numbers.lastIndex
var answerSum = Int.MAX_VALUE
var answerNumbers = Int.MAX_VALUE to Int.MAX_VALUE

while (start != end) {
val sum = numbers[start] + numbers[end]
if (sum.absoluteValue < answerSum) {
answerNumbers = numbers[start] to numbers[end]
answerSum = sum.absoluteValue
}

if (sum < 0) {
start += 1
} else if (sum > 0) {
end -= 1
} else {
println(answerNumbers.toList().joinToString(" "))
return
}
}
println(answerNumbers.toList().joinToString(" "))
}
}


fun main() {
용액().solve()
}
47 changes: 47 additions & 0 deletions src/main/kotlin/heejik/66week/혼자서 하는 틱택토.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package heejik.`66week`

private class `혼자서 하는 틱택토` {
val bingoPos = listOf(
// 가로
listOf(0 to 0, 0 to 1, 0 to 2),
listOf(1 to 0, 1 to 1, 1 to 2),
listOf(2 to 0, 2 to 1, 2 to 2),
// 세로
listOf(0 to 0, 1 to 0, 2 to 0),
listOf(0 to 1, 1 to 1, 2 to 1),
listOf(0 to 2, 1 to 2, 2 to 2),
// 대각
listOf(0 to 0, 1 to 1, 2 to 2),
listOf(2 to 0, 1 to 1, 0 to 2),
)

fun solution(board: Array<String>): Int {
var isCorrectGame = true
var isOWin = false
var isXWin = false
var OCount = 0
var XCount = 0

board.forEach { row ->
OCount += row.count { it == 'O' }
XCount += row.count { it == 'X' }
}
if (OCount - XCount !in 0..1) isCorrectGame = false

bingoPos.forEach { posList ->
val bingo = posList.map { pos ->
board[pos.first][pos.second]
}
when (bingo.joinToString("")) {
"OOO" -> isOWin = true
"XXX" -> isXWin = true
}
}

if (isOWin && isXWin) isCorrectGame = false
if (isOWin && OCount - XCount != 1) isCorrectGame = false
if (isXWin && OCount - XCount != 0) isCorrectGame = false

return if (isCorrectGame) 1 else 0
}
}

0 comments on commit 00a4495

Please sign in to comment.