Skip to content

Commit e414c4a

Browse files
committed
[BOJ] #2164.카드2 / 실버4 / 15분(∆)
1 parent f45ae26 commit e414c4a

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

learntosurf/Data Structures/2025-01-11-[BOJ]-#10773-제로.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import sys
2+
input = sys.stdin.read
3+
14
K = int(input())
25

36
stack = []
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import sys
2+
input = sys.stdin.read
3+
4+
N = int(input())
5+
L = list(range(1,N+1))
6+
7+
while (len(L)>1):
8+
L.pop(0)
9+
temp = L.pop(0)
10+
L.append(temp)
11+
12+
print(L.pop(0))
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import sys
2+
input = sys.stdin.read
3+
4+
data = input().split()
5+
N, K = int(data[0]), int(data[1]) # 멀티탭 구멍 수와 전기 용품 사용 횟수
6+
sequence = list(map(int, data[2:])) # 전기 용품 사용 순서
7+
8+
multitap = [] # 현재 멀티탭 상태
9+
unplug_count = 0 # 플러그를 뽑는 횟수
10+
11+
# 순차적으로 전기용품 사용
12+
for i in range(K):
13+
current = sequence[i]
14+
15+
# 1. 이미 멀티탭에 꽂혀 있는 경우
16+
if current in multitap:
17+
continue # 아무 작업도 하지 않고 넘어감
18+
19+
# 2. 멀티탭에 빈 자리가 있는 경우
20+
if len(multitap) < N:
21+
multitap.append(current) # 새로운 전기용품을 추가함
22+
continue
23+
24+
# 3. 멀티탭이 가득 차 있는 경우: 뽑을 전기 용품 결정
25+
farthest_idx = -1
26+
to_unplug = -1
27+
for plug in multitap:
28+
if plug not in sequence[i:]: # 앞으로 사용되지 않는 플러그
29+
to_unplug = plug
30+
break
31+
else:
32+
# 가장 나중에 사용되는 플러그
33+
idx = sequence[i:].index(plug)
34+
if idx > farthest_idx:
35+
farthest_idx = idx
36+
to_unplug = plug
37+
38+
# 플러그 교체
39+
multitap.remove(to_unplug)
40+
multitap.append(current)
41+
unplug_count += 1
42+
43+
print(unplug_count)

0 commit comments

Comments
 (0)