Skip to content

Commit 07bf7a4

Browse files
authored
Merge branch 'AlgorithmStudy-Allumbus:main' into main
2 parents dd124de + 7dd230a commit 07bf7a4

19 files changed

+420
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
'''
2+
BOJ #13335. 수강과목 (실버1)
3+
https://www.acmicpc.net/problem/13335
4+
유형: 구현, 시뮬레이션, 자료구조
5+
6+
출처:https://velog.io/@mimmimmu/12%EC%A3%BC%EC%B0%A8-%EB%B0%B1%EC%A4%80-13335%EB%B2%88-%ED%8A%B8%EB%9F%AD-%ED%8C%8C%EC%9D%B4%EC%8D%AC
7+
'''
8+
9+
10+
from collections import deque
11+
12+
n, w, L = map(int, input().split())
13+
cars = list(map(int, input().split()))
14+
15+
queue = deque()
16+
for _ in range(w):
17+
queue.append(0)
18+
19+
time = 0
20+
idx = 0
21+
while idx < n:
22+
time += 1
23+
queue.popleft()
24+
25+
if sum(queue) + cars[idx] <= L:
26+
queue.append(cars[idx])
27+
idx += 1
28+
else:
29+
queue.append(0)
30+
31+
while queue:
32+
time += 1
33+
queue.popleft()
34+
35+
print(time)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
## 🚀 12월 1주차 (12/02) 스터디 발제 주제: Implementation With Queue
2+
> 발제자: 조윤상
3+
4+
### 🗂️ 스터디 자료
5+
- PDF: [바로가기](https://github.com/AlgorithmStudy-Allumbus/codingtest_algorithm_study/blob/main/_WeeklyChallenges/W03-%5BIMPLEMENTATION%5D/Study_BOJ_1202.pdf)
6+
![image](https://github.com/user-attachments/assets/493b84c6-6c3a-4faa-85d6-0ccefde1ff78)
7+
8+
9+
### 📖 문제
10+
- [백준 #3190. 뱀](https://www.acmicpc.net/problem/3190): 구현, 시뮬레이션, 큐 / 골드5
11+
- 정답 코드: [Study_BOJ_3190_뱀.py](https://github.com/AlgorithmStudy-Allumbus/codingtest_algorithm_study/blob/main/_WeeklyChallenges/W03-%5BIMPLEMENTATION%5D/Study_BOJ_3190_%EB%B1%80.py)
12+
https://github.com/AlgorithmStudy-Allumbus/codingtest_algorithm_study/blob/aa53c6266f5a4d2a9a37b1f087511ed327e8dc59/_WeeklyChallenges/W03-%5BIMPLEMENTATION%5D/Study_BOJ_3190_%EB%B1%80.py#L8-L51
13+
14+
### 💻 과제
15+
- [백준 #13335. 트럭](https://www.acmicpc.net/problem/13335): 구현, 시뮬레이션, 큐 / 실버1
16+
- 정답 코드: [Assignment_BOJ_13335_트럭.py](https://github.com/AlgorithmStudy-Allumbus/codingtest_algorithm_study/blob/main/_WeeklyChallenges/W03-%5BIMPLEMENTATION%5D/Assignment_BOJ_13335_%ED%8A%B8%EB%9F%AD.py)
17+
https://github.com/AlgorithmStudy-Allumbus/codingtest_algorithm_study/blob/aa53c6266f5a4d2a9a37b1f087511ed327e8dc59/_WeeklyChallenges/W03-%5BIMPLEMENTATION%5D/Assignment_BOJ_13335_%ED%8A%B8%EB%9F%AD.py#L10-L35
944 KB
Binary file not shown.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
'''
2+
BOJ #3190. 뱀 (골드5)
3+
https://www.acmicpc.net/problem/3190
4+
유형: 구현, 시뮬레이션, 자료구조
5+
'''
6+
7+
8+
import sys
9+
from collections import deque
10+
input = sys.stdin.readline
11+
n = int(input())
12+
k = int(input())
13+
maps = [[0] * (n+1) for _ in range(n+1)]
14+
for _ in range(k):#사과의 위치
15+
x,y = map(int,input().split())
16+
maps[x][y] = 2
17+
info = {}
18+
l = int(input())
19+
for _ in range(l):# 뱀의 방향변환정보 (초, 방향 L:왼쪽 D:오른쪽)
20+
sec, direct = input().split()
21+
info[int(sec)] = direct
22+
time = 0
23+
dx = [1,0,-1,0]
24+
dy = [0,1,0,-1]
25+
x, y = 1, 1
26+
maps[y][x] = 1
27+
d = 0
28+
snakes = deque([(1, 1)])
29+
30+
while True:
31+
nx, ny = x+dx[d], y+dy[d]
32+
# 뱀의 몸통에 닿거나 벽에 부딪히는 경우 종료
33+
if nx<=0 or ny<=0 or nx>n or ny>n or (nx,ny) in snakes:
34+
break
35+
# 사과를 먹지 못하면 꼬리 없애기
36+
if maps[ny][nx]!=2:
37+
a,b = snakes.popleft()
38+
maps[b][a]=0
39+
x, y = nx, ny
40+
maps[y][x] = 1
41+
snakes.append((nx, ny))
42+
time+=1
43+
44+
# 시간에 해당하는 방향전환 정보가 있을 경우
45+
if time in info.keys():
46+
if info[time] == "D":
47+
d = (d+1)%4
48+
else:
49+
nd = 3 if d==0 else d-1
50+
d = nd
51+
print(time+1)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import sys
2+
input = sys.stdin.readline
3+
4+
N, K = map(int, input().split()) # 물품의 개수, 버틸 수 있는 무게
5+
6+
items = []
7+
for _ in range(N):
8+
W, V = map(int, input().split())
9+
items.append((W, V)) # (물건의 개수, 물건의 가치)
10+
11+
def backpack(N, K, items):
12+
dp = [0] * (K+1) # 배낭 크기만큼 DP 테이블 초기화
13+
14+
for weight, value in items:
15+
for w in range(K, weight-1, -1): # 역순으로 반복
16+
dp[w] = max(dp[w], dp[w-weight] + value)
17+
18+
return dp[K]
19+
20+
print(backpack(N, K, items))
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
n = int(input())
2+
3+
def fibonacci(n):
4+
dp = [0] * (n+1)
5+
6+
dp[0] = 0
7+
dp[1] = 1
8+
9+
for i in range(2, n+1):
10+
dp[i] = dp[i-1] + dp[i-2]
11+
12+
return dp[n]
13+
14+
print(fibonacci(n))
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
N = int(input())
2+
3+
def operation(N):
4+
dp = [0] * (N+1)
5+
6+
for i in range(2, N+1): # 1은 연산이 필요하지 않음
7+
dp[i] = dp[i-1] + 1
8+
9+
if i%2==0:
10+
dp[i] = min(dp[i], dp[i//2]+1)
11+
12+
if i%3==0:
13+
dp[i] = min(dp[i], dp[i//3]+1)
14+
15+
return dp[N]
16+
17+
print(operation(N))
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import sys
2+
input = sys.stdin.readline
3+
4+
N = int(input())
5+
stair = [int(input()) for _ in range(N)]
6+
7+
# N에 따른 예외 처리
8+
if N == 1:
9+
print(stair[0])
10+
exit()
11+
12+
if N == 2:
13+
print(stair[0] + stair[1])
14+
exit()
15+
16+
dp = [0] * (N+1)
17+
dp[0] = stair[0]
18+
dp[1] = stair[0] + stair[1]
19+
dp[2] = max(stair[0] + stair[2], stair[1] + stair[2])
20+
21+
for i in range(3, N):
22+
dp[i] = max(dp[i-2] + stair[i], dp[i-3] + stair[i-1] + stair[i])
23+
24+
print(dp[N-1])
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import sys
2+
input = sys.stdin.readline
3+
INF = sys.maxsize
4+
5+
N = int(input())
6+
blocks = input().split()
7+
8+
dp = [INF] * N
9+
dp[0] = 0 # 1번 블록에서 출발
10+
11+
for i in range(1, N): # 목표 블록 (1번 블록 이후부터 N번까지)
12+
for j in range(i): # 이전 블록들 (0번부터 i-1번까지 탐색)
13+
if blocks[j] == 'B' and blocks[i] != 'O':
14+
continue
15+
elif blocks[j] == 'O' and blocks[i] != 'J':
16+
continue
17+
elif blocks[j] == 'J' and blocks[i] != 'B':
18+
continue
19+
dp[i] = min(dp[i], dp[j] + (i-j)**2)
20+
21+
if dp[-1] == INF:
22+
print(-1)
23+
else:
24+
print(dp[-1])
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import sys
2+
input = sys.stdin.readline
3+
4+
N,S,M = map(int,input().split())
5+
V = list(map(int,input().split()))
6+
7+
dp = [[0]*(M+1) for _ in range(N+1)]
8+
dp[0][S] = 1 # 시작 볼륨을 설정
9+
10+
for i in range(1, N+1): # 각 곡에 대해
11+
for j in range(M+1): # 가능한 볼륨에 대해
12+
if dp[i-1][j] != 0: # 이전 곡에서 해당 볼륨이 가능하다면
13+
if 0 <= j + V[i-1] <= M: # 볼륨을 올릴 수 있다면
14+
dp[i][j + V[i-1]] = 1
15+
if 0 <= j - V[i-1] <= M: # 볼륨을 낮출 수 있다면
16+
dp[i][j-V[i-1]] = 1
17+
volume = -1
18+
for i in range(M, -1, -1): # 최대 볼륨부터 탐색
19+
if dp[N][i] == 1: # 가능한 볼륨을 찾으면
20+
volume = i
21+
break
22+
23+
print(volume)

0 commit comments

Comments
 (0)