-
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
[Week4] 전현수: 근손실, 톱니바퀴, 트리의 부모 찾기, 회의실 배정, 지름길 #18
Open
soopeach
wants to merge
6
commits into
main
Choose a base branch
from
4week/hyunsoo
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+421
−0
Open
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Feat: 회의실 배정 추가
- Loading branch information
commit 960965705c56dfb0d017b9a70397cbb669f2d279
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package `4week`.hyunsoo | ||
|
||
/** | ||
* <문제> | ||
* [회의실 배정](https://www.acmicpc.net/problem/1931) | ||
* | ||
* 한 개의 회의실이 있는데 이를 사용하고자 하는 N개의 회으ㅔㅇ 대하여 회의실 사용표를 만드려고 함. | ||
* 각 회의 I에 대해 시작시간과 끝나는 시간이 주어져있고, 각 회의가 겹치지 않게 하면서 회의실을 사용할 수 있는 회의의 최대 개수 찾기 | ||
* | ||
* 아이디어 | ||
* - 회의의 수가 100,000개라 완탐은 불가능 | ||
*/ | ||
|
||
class 전현수_회의실_배정{ | ||
|
||
data class MeetingData(val start: Int, val end: Int) | ||
|
||
fun solution() { | ||
|
||
val meetingCnt = readln().toInt() | ||
val meetingList = mutableListOf<MeetingData>() | ||
var canMeetingCnt = 0 | ||
var endTime = 0 | ||
|
||
repeat(meetingCnt) { | ||
val (start, end) = readln().split(" ").map { it.toInt() } | ||
meetingList.add(MeetingData(start, end)) | ||
} | ||
|
||
// 정렬 | ||
meetingList.sortWith(compareBy<MeetingData> { it.end }.thenBy { it.start }) | ||
Comment on lines
+21
to
+31
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. 소팅을 통해 추가해야 하는 경우에는 PriorityQueue를 이용해봐요 val pq = PriorityQueue(compareBy<MeetingData> { it.end }.thenBy { it.start }) |
||
|
||
// 정렬된 첫 미팅은 반드시 해야지! | ||
endTime = meetingList.first().end | ||
canMeetingCnt++ | ||
|
||
meetingList.drop(1).forEach { meetingData -> | ||
if (endTime <= meetingData.start) { | ||
endTime = meetingData.end | ||
canMeetingCnt++ | ||
} | ||
} | ||
Comment on lines
+34
to
+42
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. pq를 사용하면 drop 처리 안하고 그냥 뽑아주면 되겠죠? endTime = pq.poll().end
canMeetingCnt++
while (pq.isNotEmpty()) {
val meetingData = pq.poll()
if (endTime <= meetingData.start) {
endTime = meetingData.end
canMeetingCnt++
}
} |
||
|
||
println(canMeetingCnt) | ||
} | ||
|
||
} | ||
|
||
fun main(){ | ||
val myClass = 전현수_회의실_배정() | ||
myClass.solution() | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
항상 전역변수를 선언해줘야한다는 부분을 사용하는 부분에만 적용한다 생각해보시면 아래 endTime을 사용하는 부분에서 var 선언해주면 되지 않았을까 싶어요!