Skip to content

Commit 3dea476

Browse files
authored
Merge pull request #113 from zaqquum/main
Hongjoo/12์›”4์ฃผ์ฐจ/5๊ฐœ
2 parents 56e2d8b + f44f497 commit 3dea476

5 files changed

+191
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"""
2+
input : ์ด ์œ ์ œํ’ˆ ์ˆ˜ N , ๊ฐ ์ œํ’ˆ ๊ฐ€๊ฒฉ
3+
goal : ๋ชจ๋‘ ์‚ด๋•Œ ์ตœ์†Œ ๋น„์šฉ
4+
Condition
5+
1. 3๊ฐœ ์ค‘ ๊ฐ€์žฅ ์‹ผ๊ฒƒ๋งŒ ๋ฌด๋ฃŒ, ๋‚˜๋จธ์ง€ 2๊ฐœ๋Š” ๊ฐ€๊ฒฉ ์ง€๋ถˆ
6+
7+
# Flow(greedy)
8+
1. 3๊ฐœ์”ฉ ๋ฌถ๊ธฐ
9+
- ๊ฐ’์ด ํฐ ๋†ˆ๋“ค ์ˆœ์œผ๋กœ ์ •๋ ฌ
10+
2. ๊ฐ ๋ฌถ์Œ ๋ณ„ ์ œ์ถœ ๊ฐ€๊ฒฉ count ํ•˜๊ธฐ
11+
12+
๋ฌธ์ œ : https://www.acmicpc.net/problem/11508
13+
"""
14+
15+
import sys
16+
input = sys.stdin.readline
17+
n = int(input())
18+
products = list()
19+
# 1. price ์ž…๋ ฅ ๋ฐ›๊ธฐ
20+
for i in range(n):
21+
each_price = int(input())
22+
products.append(each_price)
23+
24+
# 2. ๊ฐ€๊ฒฉ ๋น„์‹ผ ์ˆœ = priority์œผ๋กœ item ์ •๋ ฌ
25+
products = sorted(products , reverse= True)
26+
print(products)
27+
# 2. for ๋ฌธ์œผ๋กœ ์ด price ๊ณ„์‚ฐํ•˜๊ธฐ
28+
# ์ด๋•Œ item 3๊ฐœ ๋ฌถ์Œ์ด ์ถฉ์กฑ ๋˜๋ฉด, 3๊ฐœ์ค‘ ์ตœ์†Œ ๊ฐ€๊ฒฉ์„ ์ „์ฒด price ์—์„œ ๋นผ๊ธฐ
29+
bags = list()
30+
total = 0
31+
for item in products :
32+
if len(bags) < 3 :
33+
bags.append(item)
34+
total += item
35+
# print(bags)
36+
if len(bags) == 3 :
37+
free = min(bags)
38+
total -= free
39+
bags = []
40+
print(total)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""
2+
#15650. N๊ณผM(2)
3+
https://www.acmicpc.net/problem/15650
4+
5+
- ์กฐํ•ฉ : 1~ N ์ค‘ m๊ฐœ๋กœ ๊ตฌ์„ฑ๋œ ์ˆ˜์—ด ์ถœ๋ ฅํ•˜๊ธฐ
6+
- ์‚ฌ์ „์ˆœ์œผ๋กœ ์ฆ๊ฐ€ํ•˜๋Š” ํ•˜๋Š” ์ˆœ์„œ๋กœ ์ถœ๋ ฅ
7+
- backtracking
8+
"""
9+
import sys
10+
n , m = map(int, sys.stdin.readline().split())
11+
# 1. ์ˆ˜์—ด ํ›„๋ณด๊ตฐ ๋‚˜์—ดํ•˜๊ธฐ
12+
board = list(range(n+1)) # [1,2,...n]
13+
#2. m ๊ฐœ์˜ ์ˆ˜์—ด ์กฐํ•ฉ ์ถœ๋ ฅํ•˜๊ธฐ
14+
stack = list()
15+
result = list()
16+
def backtracking(start , end ,m) :
17+
if len(stack) == m : # ์žฌ๊ท€ ์ข…๋ฃŒ ์กฐ๊ฑด
18+
print(" ".join(map(str, stack)))
19+
return
20+
21+
for i in range(start, end+1) : # ๋ชจ๋“  ์ž์‹ ๋…ธ๋“œ ๋‚˜์—ด
22+
if i not in stack : # ์„ ํƒ์ง€ ์œ ํšจ ์—ฌ๋ถ€ ํ™•์ธ - ์ค‘๋ณต ํ™•์ธ
23+
stack.append(i) # ์ž์‹ ๋…ธ๋“œ ์ถ”๊ฐ€
24+
backtracking(i+1 , end , m) # ๋ฐฑ ํŠธ๋ž˜ํ‚น
25+
stack.pop() # ๋ถ€๋ชจ ๋…ธ๋“œ๋กœ ํšŒ๊ท€
26+
backtracking(1,n, m)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"""
2+
๋ฐฑ์ค€ #11053. ๊ฐ€์žฅ ๊ธด ์ฆ๊ฐ€ํ•˜๋Š” ๋ถ€๋ถ„ ์ˆ˜์—ด
3+
https://www.acmicpc.net/problem/11053
4+
5+
# Intutition : DP
6+
7+
๊ฐ€์žฅ ๊ธด ์ฆ๊ฐ€ํ•˜๋Š” ๋ถ€๋ถ„์ˆ˜์—ด
8+
=> ๋ถ€๋ถ„์ˆ˜์—ด ๋‚ด ์ตœ๋Œ€๊ฐ’๋ณด๋‹ค ํฌ๋ฉด, ๋ถ€๋ถ„์ˆ˜์—ด์— ์ถ”๊ฐ€ & ๊ธฐ์ค€ ์ตœ๋Œ€ ๊ฐ’ ์—…๋ฐ์ดํŠธ
9+
10+
# set ์€ ์‚ฝ์ž…์‹œ ์ˆœ์„œ๋ฅผ ๋ณด์žฅํ•˜์ง€ ์•Š์Œ(์ˆœ์„œ ์—†๋Š” ์ž๋ฃŒํ˜• , ์ฆ‰ ์ถœ๋ ฅ ๋ฐ ์‚ฝ์ž…์‹œ ๋žœ๋คํ•˜๊ฒŒ ์„ž์ž„)
11+
https://okky.kr/questions/571601
12+
"""
13+
import sys
14+
15+
N = int(sys.stdin.readline())
16+
input_list = list(map(int, sys.stdin.readline().split()))
17+
# dp[i] : 0~ i๋ฒˆ์งธ Subset ์ค‘ ๊ฐ€์žฅ ๊ธด ์ฆ๊ฐ€ํ•˜๋Š” ๋ถ€๋ถ„ ์ˆ˜์—ด ๊ฐฏ์ˆ˜
18+
#
19+
# Subset ์ค‘ ๊ฐ€์žฅ ํฐ ์ˆ˜ ์ฐพ๊ธฐ(๋น„๊ต๊ตฐ)
20+
# ๋น„๊ต๊ตฐ VS ํ˜„์žฌ๊ฐ’ -> ํฌ๋ฉด dp +1 , ์ž‘์œผ๋ฉด dp
21+
22+
# 0. dp ์ดˆ๊ธฐ๊ฐ’ : Subset ์ด ๊ฐœ์ˆ˜
23+
dp = [ 1 for _ in range(N)]
24+
for i in range(1, N) :
25+
for j in range(i):
26+
if input_list[i] > input_list[j] :
27+
dp[i] = max(dp[i] , dp[j]+1)
28+
29+
30+
31+
print(max(dp))
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
"""
2+
์ฝ˜์„ผํŠธ์— ๋‚จ์€ ๊ธฐ๊ธฐ ์ค‘ ๋‹ด ์ˆœ๋ฒˆ ์—†๊ฑฐ๋‚˜ ๊ฐ€์žฅ ๋‚˜์ค‘์ธ ๊ฒƒ ๋ถ€ํ„ฐ ๊ต์ฒด
3+
DP..?
4+
"""
5+
import sys
6+
N , K = map(int,sys.stdin.readline().split())
7+
#1. ์‚ฌ์šฉ์ˆœ์„œ
8+
use_case = list(map(int,sys.stdin.readline().split()))
9+
timelines =[[] for _ in range(K+1)] # idx : ๊ธฐ๊ธฐ ๋ฒˆํ˜ธ, value : times(์ˆœ๋ฒˆ)
10+
11+
# 2. dp ๋ฆฌ์ŠคํŠธ ๋งŒ๋“ค๊ธฐ
12+
for name in range(len(use_case)): # 0~k ์ดˆ
13+
for idx in range(1,K+1): # 1~k๋ฒˆํ˜ธ device
14+
if idx == use_case[name]:
15+
timelines[idx].append(name)
16+
17+
# ์‹œ๊ฐ„ ๋ณ„๋กœ plug in ์—…๋ฐ์ดํŠธ
18+
# plug in ํ•œ ๊ธฐ๊ธฐ ์ค‘ ๋‹ค์Œ ์—…๋ฐ์ดํŠธ๊ฐ€ ๋Šฆ๋Š” ๊ธฐ๊ธฐ ๋ถ€ํ„ฐ plut out -> ๊ต์ฒด
19+
20+
cnt = 0
21+
current_plug = []
22+
for time in range(K):
23+
current_device = use_case[time]
24+
#0. current_device๊ฐ€ ํ˜„์žฌ plug์— ๊ทธ๋Œ€๋กœ ์กด์žฌํ•˜๋Š” ๊ฒฝ์šฐ , continue
25+
if current_device in current_plug :
26+
timelines[current_device].pop(0)
27+
continue
28+
29+
#1. plug ๊ฐ€ ๋‚จ์œผ๋ฉด -> ๊ทธ๋ƒฅ ๋„ฃ๊ธฐ
30+
if len(current_plug) < N :
31+
current_plug.append(current_device)
32+
timelines[current_device].pop(0)
33+
34+
#2. plug ๊ณต๊ฐ„ ์—†์œผ๋ฉด -> plug outํ•  ๊ฒƒ ์ฐพ๊ธฐ-> ๊ต์ฒด
35+
else :
36+
changed_device_idx = 0
37+
plug_out_hole = 0
38+
for hole in range(N) :
39+
if len(timelines[current_plug[hole]]) <=0 : # ๋งŒ์•ฝ ๋‹ค์Œ ์ˆœ๋ฒˆ์—์„œ ์‚ฌ์šฉ ์•ˆํ•˜๋Š” ๊ฒฝ์šฐ , ๋ฐ”๋กœ ๊ต์ฒด ์žฅ์น˜๋กœ ์„ ์ •
40+
plug_out_hole = hole
41+
break
42+
if timelines[current_plug[hole]][0] >changed_device_idx:
43+
changed_device_idx = timelines[current_plug[hole]][0] # next time
44+
plug_out_hole = hole
45+
#plug out
46+
cnt += 1
47+
current_plug.pop(plug_out_hole)
48+
# ๊ต์ฒด
49+
current_plug.append(current_device)
50+
timelines[current_device].pop(0)
51+
52+
print(cnt)
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)