728x90
반응형
그리디 알고리즘 문제이다. 정렬을 사용하면 쉽게 풀 수 있다!
lambda를 사용해 끝나는 시간과 시작하는 시간 순으로 두 번 정렬해주는 게 핵심이다.
li = [list(map(int, input().split())) for _ in range(int(input()))]
li.sort(key=lambda x : (x[1], x[0]))
cnt = 1
end_time = li[0][1]
for i in range(1, len(li)):
if li[i][0] >= end_time:
cnt += 1
end_time = li[i][1]
print(cnt)
728x90
반응형
'Agorithm > 백준 알고리즘' 카테고리의 다른 글
백준 알고리즘 1940번 주몽(python) (0) | 2020.02.04 |
---|---|
백준 알고리즘 1932번 정수삼각형(python) (0) | 2020.02.04 |
백준 알고리즘 1934번 최소공배수(python) (0) | 2020.02.04 |
백준 알고리즘 1453번 피시방 알바(python) (0) | 2020.02.04 |
백준 알고리즘 1350번 진짜 공간(python) (0) | 2020.02.04 |