알고리즘 분류 : 그리디 알고리즘
https://www.acmicpc.net/problem/1700
1700번: 멀티탭 스케줄링
기숙사에서 살고 있는 준규는 한 개의 멀티탭을 이용하고 있다. 준규는 키보드, 헤어드라이기, 핸드폰 충전기, 디지털 카메라 충전기 등 여러 개의 전기용품을 사용하면서 어쩔 수 없이 각종 전
www.acmicpc.net
[ 코드 ]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
n, k = map(int, input().split())
t = list(map(int, input().split()))
plug = [0] * n
cnt = 0
idx = pos = ch_idx = 0
for i in t:
if not i in plug:
if 0 in plug:
plug[plug.index(0)] = i
else:
for j in plug:
if not j in t[idx:]:
ch_idx = j
break
elif t[idx:].index(j) > pos:
ch_idx = j
pos = t[idx:].index(j)
plug[plug.index(ch_idx)] = i
ch_idx = pos = 0
cnt += 1
idx += 1
print(cnt)
|
'코딩 > 백준' 카테고리의 다른 글
[백준] 2840번 : 행운의 바퀴 (Python 파이썬) (0) | 2021.04.04 |
---|---|
[백준] 1091번 : 카드 섞기 (Python 파이썬) (0) | 2021.04.03 |
[백준] 2858번 : 기숙사 바닥 (Python 파이썬) (0) | 2021.02.21 |
[백준] 5462번 : POI (Python 파이썬) (0) | 2021.02.17 |
[백준] 20114번: 미아 노트 (Python 파이썬) (0) | 2021.02.16 |