본문 바로가기

코딩/백준

[백준] 1700번 : 멀티탭 스케줄링 (Python 파이썬)

알고리즘 분류 : 그리디 알고리즘

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())
= 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)