Skip to content

Commit b1c1de6

Browse files
committed
Add study materials and soltuions
1 parent 1280e96 commit b1c1de6

File tree

4 files changed

+64
-0
lines changed

4 files changed

+64
-0
lines changed

β€Ž_WeeklyChallenges/W05-[Greedy]/Assignment_BOJ_1931_νšŒμ˜μ‹€λ°°μ •.pyβ€Ž

Whitespace-only changes.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## πŸš€ 12μ›” 4μ£Όμ°¨ (12/23) μŠ€ν„°λ”” 발제 주제: Greedy Algorithm
2+
> 발제자: μ •μˆ˜λ―Έ
3+
4+
### πŸ—‚οΈ μŠ€ν„°λ”” 자료
5+
- PDF: [λ°”λ‘œκ°€κΈ°]()
6+
![image](https://github.com/user-attachments/assets/eda88039-4fa3-4c7e-8f0e-b610faa8081a)
7+
8+
9+
### πŸ“– 문제
10+
- [λ°±μ€€ #1700. λ©€ν‹°νƒ­ μŠ€μΌ€μ€„λ§](https://www.acmicpc.net/problem/1700): 그리디 / κ³¨λ“œ1
11+
- μ •λ‹΅ μ½”λ“œ: [Study_BOJ_3190_λ±€.py]()
12+
13+
### πŸ’» 과제
14+
- [λ°±μ€€ #1931. 트럭](https://www.acmicpc.net/problem/1931): 그리디, μ •λ ¬ / 싀버1
15+
- μ •λ‹΅ μ½”λ“œ: [Assignment_BOJ_1931_νšŒμ˜μ‹€λ°°μ •.py]()
422 KB
Binary file not shown.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
'''
2+
BOJ #1700. λ©€ν‹°νƒ­ μŠ€μΌ€μ€„λ§ (κ³¨λ“œ1)
3+
https://www.acmicpc.net/problem/1700
4+
μœ ν˜•: Greedy
5+
'''
6+
7+
import sys
8+
input = sys.stdin.read
9+
10+
data = input().split()
11+
N, K = int(data[0]), int(data[1]) # λ©€ν‹°νƒ­ ꡬ멍 μˆ˜μ™€ μ „κΈ° μš©ν’ˆ μ‚¬μš© 횟수
12+
sequence = list(map(int, data[2:])) # μ „κΈ° μš©ν’ˆ μ‚¬μš© μˆœμ„œ
13+
14+
multitap = [] # ν˜„μž¬ λ©€ν‹°νƒ­ μƒνƒœ
15+
unplug_count = 0 # ν”ŒλŸ¬κ·Έλ₯Ό λ½‘λŠ” 횟수
16+
17+
# 순차적으둜 μ „κΈ°μš©ν’ˆ μ‚¬μš©
18+
for i in range(K):
19+
current = sequence[i]
20+
21+
# 1. 이미 멀티탭에 κ½‚ν˜€ μžˆλŠ” 경우
22+
if current in multitap:
23+
continue # 아무 μž‘μ—…λ„ ν•˜μ§€ μ•Šκ³  λ„˜μ–΄κ°
24+
25+
# 2. 멀티탭에 빈 μžλ¦¬κ°€ μžˆλŠ” 경우
26+
if len(multitap) < N:
27+
multitap.append(current) # μƒˆλ‘œμš΄ μ „κΈ°μš©ν’ˆμ„ 좔가함
28+
continue
29+
30+
# 3. 멀티탭이 가득 μ°¨ μžˆλŠ” 경우: 뽑을 μ „κΈ° μš©ν’ˆ κ²°μ •
31+
farthest_idx = -1
32+
to_unplug = -1
33+
for plug in multitap:
34+
if plug not in sequence[i:]: # μ•žμœΌλ‘œ μ‚¬μš©λ˜μ§€ μ•ŠλŠ” ν”ŒλŸ¬κ·Έ
35+
to_unplug = plug
36+
break
37+
else:
38+
# κ°€μž₯ λ‚˜μ€‘μ— μ‚¬μš©λ˜λŠ” ν”ŒλŸ¬κ·Έ
39+
idx = sequence[i:].index(plug)
40+
if idx > farthest_idx:
41+
farthest_idx = idx
42+
to_unplug = plug
43+
44+
# ν”ŒλŸ¬κ·Έ ꡐ체
45+
multitap.remove(to_unplug)
46+
multitap.append(current)
47+
unplug_count += 1
48+
49+
print(unplug_count)

0 commit comments

Comments
Β (0)