Skip to content

Commit a21bea3

Browse files
committed
[BOJ]#1931.회의실배정/ 골드5/ 2hour
https://www.acmicpc.net/problem/1931
1 parent 8e5891f commit a21bea3

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

Hongjoo/백준/회의실배정.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"""
2+
# goal:회의 시간이 겹치지 않는 회의의 최대 개수 -> 최적의 해
3+
-조건
4+
1. 입력 - 각 회의 I : (시작 시간 , 끝나는 시간)
5+
2 회의는 중단 될 수 없ㅇ,ㅁ
6+
3. 회의 시작 시간 = 끝나는 시간
7+
4. 0 <= 시작시간, 끝나는 시간 <= 2^31 -1
8+
9+
# intution : 그리디
10+
- prioirt 정렬
11+
12+
"""
13+
import sys
14+
from collections import deque
15+
# 0. 회의 리스트 입력 받기 [[시작 시간, 끝나는 시간]]
16+
N = int(sys.stdin.readline())
17+
cov_list =deque()
18+
19+
for n in range(N) :
20+
start , end = map(int, sys.stdin.readline().split())
21+
cov_list.append((start ,end))
22+
23+
# 2. 회의 prioirty 기준으로 정렬 -> prior : (1) end time 이 빠른 순 (2) start 가 빠른 순 으로 정렬
24+
cov_list = deque(sorted(cov_list , key = lambda x : x[0]))
25+
cov_list = deque(sorted(cov_list , key = lambda x : x[1]))
26+
27+
# # conv_lisg : [[1, 4], [3, 5], [0, 6], [5, 7], [3, 8], [5, 9], [6, 10], [8, 11], [8, 12], [2, 13], [12, 14]]
28+
#
29+
# (1) 회의실 뽑기
30+
# 2-1 현재 회의 종료 시간 보다 end 가 작으면 -> 제외
31+
# 2-2 같거나 크면 -> 회의실 업데이트 (cnt+1)
32+
cnt = 0
33+
finished_time = 0
34+
for idx in range(N) :
35+
start , end = cov_list[idx]
36+
if finished_time <= start :
37+
38+
finished_time= end
39+
cnt +=1
40+
print(cnt)
41+
42+

0 commit comments

Comments
 (0)