728x90
회의실 배정
https://www.acmicpc.net/problem/1931
문제

코드
- 그리디를 활용한 풀이
- 끝나는 시간을 기준으로 정렬, 다음 회의 시간이 빨리 끝나는 것을 선택
# 회의실 배정
# 1931
import sys
input = sys.stdin.readline
N = int(input())
time = []
count = 1
for i in range(N):
start, end = map(int, input().split())
time.append((start, end))
time.sort(key = lambda x: (x[1], x[0]))
end = time[0][1]
for i in range(1, N):
if time[i][0] >= end:
end = time[i][1]
count += 1
print(count)
728x90
반응형
'Algorithm > 백준' 카테고리의 다른 글
[백준] 스택 2 - 파이썬 (0) | 2024.06.21 |
---|---|
[백준] 주유소 - 파이썬 (0) | 2024.06.21 |
[백준] 동전 0 - 파이썬 (0) | 2024.06.20 |
[백준] 우유 축제 - 파이썬 (0) | 2024.06.20 |
[백준] 5와 6의 차이 - 파이썬 (0) | 2024.06.20 |
728x90
회의실 배정
https://www.acmicpc.net/problem/1931
문제

코드
- 그리디를 활용한 풀이
- 끝나는 시간을 기준으로 정렬, 다음 회의 시간이 빨리 끝나는 것을 선택
# 회의실 배정
# 1931
import sys
input = sys.stdin.readline
N = int(input())
time = []
count = 1
for i in range(N):
start, end = map(int, input().split())
time.append((start, end))
time.sort(key = lambda x: (x[1], x[0]))
end = time[0][1]
for i in range(1, N):
if time[i][0] >= end:
end = time[i][1]
count += 1
print(count)
728x90
반응형
'Algorithm > 백준' 카테고리의 다른 글
[백준] 스택 2 - 파이썬 (0) | 2024.06.21 |
---|---|
[백준] 주유소 - 파이썬 (0) | 2024.06.21 |
[백준] 동전 0 - 파이썬 (0) | 2024.06.20 |
[백준] 우유 축제 - 파이썬 (0) | 2024.06.20 |
[백준] 5와 6의 차이 - 파이썬 (0) | 2024.06.20 |