Created
March 5, 2018 10:08
-
-
Save qkreltms/85772a2da209e68b41264f641adf160b to your computer and use it in GitHub Desktop.
백준1931 회의실배정 https://www.acmicpc.net/problem/1931 python
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
# 앞, 뒤 두번 정렬 하는 이유는 [1, 1], [2, 2], [1, 2], [2, 2]같은 반례가 있음 | |
class Meeting: | |
def __init__(self, begin, end): | |
self.begin = begin | |
self.end = end | |
def algorithm1931(): | |
meeting_list = [] | |
for x in range(int(input())): | |
temp = list(map(int, input().split())) | |
meeting_list.append(Meeting(temp[0], temp[1])) | |
meeting_list = sorted(meeting_list, key=lambda m: m.begin) # 앞에 것 기준으로 오름차순 정렬 | |
meeting_list = sorted(meeting_list, key=lambda m: m.end) # 뒤에 것 기준으로 오름차순 정렬 | |
begin = 0 | |
ctn = 0 | |
for m in meeting_list: | |
if begin <= m.begin: | |
begin = m.end | |
ctn += 1 | |
print(ctn) | |
algorithm1931() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment