Skip to content

Commit fb082c8

Browse files
committed
2 parents 2ec53d9 + 449b815 commit fb082c8

28 files changed

+874
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
def solution(s):
2+
answer = ""
3+
s = s.split(' ') # 1.단어별로 splite 된 list
4+
for i in range(len(s)) : #2.각 단어별로 맨 앞글자 대문자,그외 소문자로 변환
5+
#capitalize : 첫문자는 대문자,그외는 소문자로 만듦
6+
s[i] = s[i].capitalize()
7+
answer = " ".join(s)#3. 분리해둔 단어들을 한개의 str로 합치기
8+
9+
return answer

Hongjoo/백준/뱀.py

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
"""
2+
condition
3+
1. NxN map , some apple , N+1 walls ,
4+
2. snack 's time : size = 0 : 1 , right way
5+
6+
Rule
7+
1.먼저 뱀은 몸길이를 늘려 머리를 다음칸에 위치시킨다.
8+
2.만약 벽,자기자신의 몸과 부딪히면 게임이 끝난다. =game over 조건
9+
<사과 - 몸길이 변화 >
10+
3.만약 이동한 칸에 사과 O => 그 칸에 있던 사과가 없어지고 꼬리 stay , 머리 길어짐 => 즉 몸길이 변함
11+
4.만약 이동한 칸에 사과 X => 몸길이를 줄여서 꼬리가 위치한 칸을 비워준다(즉, 담칸으로 이동만 함). 즉, 몸길이는 변하지 않는다.
12+
-> 머리 부터 ,그리고 꼬리 이동(사과 유무)
13+
#Variable
14+
1. time , 2. 뱀이 차지하는 영역 : stack , 3.
15+
16+
Flow
17+
1. 입력을 통해 map, 이동 반경
18+
19+
20+
"""
21+
import sys
22+
23+
''' 1. 입력 값 변수에 할당(field구축 , 뱀의 방향 정보)
24+
- field : N+2
25+
빈 곳 = 0
26+
벽, 뱀의 위치 = -1
27+
사과 = 1
28+
'''
29+
30+
N = int(sys.stdin.readline()) # 보드 크기 => N+2*(q)
31+
K = int(sys.stdin.readline()) # 사과 개수
32+
33+
field = [[0 for _ in range(N+2)] for k in range(N+2)]
34+
# 뱀의 첫 위치 & 벽
35+
field[1][1] = -1
36+
for i in range(len(field)):
37+
for j in range(len(field[0])) :
38+
if i in [0, N+1] or j in [0,N+1] :
39+
field[i][j] = -1
40+
41+
# 사과 위치
42+
for k in range(K) :
43+
i , j = map(int, sys.stdin.readline().split())
44+
field[i][j] = 1
45+
46+
# 뱀의 방향 정보 -> rotate_time=[time, direction] # 방향을 이동하기 전에 확인하여 t+1 로 저장
47+
48+
L = int(sys.stdin.readline())
49+
rotate_time = []
50+
for l in range(L):
51+
t , d = sys.stdin.readline().split()
52+
rotate_time.append([int(t)+1,d])
53+
54+
55+
"""
56+
2. 게임 start
57+
- 뱀의 현재 차지하고 있는 위치 : snack = [[머리 좌표] , [몸통 좌표들],...,[꼬리 좌표]]
58+
- & 차지하는 field = -1
59+
(1) 뱀이 도착한 위치의 field 번호 = -1(본인,벽) 이 아닐때 까지 이동
60+
"""
61+
def change_int_direction(time, current_direction) : # 방향 변환
62+
direction_map = ['r','d','l','t'] * 2
63+
# direction_dict = {'r,':[0,1] ,'d' :[-1,0] ,'l':[0,-1] , 't':[1,0] }
64+
for ch_t, ch_d in rotate_time :
65+
if time == ch_t : # {'r,':[0,1] ,'d' :[-1,0] ,'l':[0,-1] , 't':[1,0] }
66+
# print(f"change direction ")
67+
idx = direction_map.index(current_direction)
68+
if ch_d == "D" : #right
69+
current_direction = direction_map[idx + 1]
70+
elif ch_d == "L" :#left
71+
current_direction = direction_map[idx - 1]
72+
break
73+
74+
# direction = direction_dict[current_direction] # [0,1]
75+
return current_direction # [0,1]
76+
from collections import deque
77+
time = 0
78+
snack = deque() # idx =0 머리 , -1 꼬리
79+
snack_direction = 'r' # r,d,l, u
80+
snack.append([1,1])
81+
direction_dict = {'r':[0,1] ,'d' :[1,0] ,'l':[0,-1] , 't':[-1,0] }
82+
while(1) :
83+
time += 1
84+
# print(f"##time : {time}")
85+
# 사과 확인
86+
head_x , head_y = snack[0]
87+
#1. head 이동 - snack 영역 추가
88+
snack_direction = change_int_direction(time, snack_direction)
89+
move_x , move_y = direction_dict[snack_direction]
90+
head_x += move_x ; head_y += move_y
91+
# print(f"- snack_direction : {snack_direction} # {move_x},{move_y}")
92+
# print(f"new head : {head_x} , {head_y}")
93+
#2.현재 head 위치하는 곳의 조건 확인
94+
if field[head_x][head_y] == -1 : #game over
95+
# print(f"!!!gameover : ")
96+
# print(field)
97+
# print(f"{head_x} , {head_y} = {field[head_x][head_y]}")
98+
break
99+
elif field[head_x][head_y] == 0 : # safe(빈곳)
100+
tail_x , tail_y = snack.pop() #W 꼬리 이동
101+
field[tail_x][tail_y] = 0
102+
# field[head_x][head_y] == 0,1 (사과, 빈곳 )공통점 - 머리 이동 ,
103+
field[head_x][head_y] = -1 #field 값 변경(뱀이 차지함) - 사과 먹음
104+
snack.appendleft([head_x,head_y]) # head 추가
105+
# print(snack)
106+
print(time)

Hongjoo/백준/트럭.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# 실패
2+
import sys
3+
n, w, l = map(int, sys.stdin.readline().split())
4+
truck = list(map(int, sys.stdin.readline().split()))
5+
time, bridge = 0, [0]*w #1. 시간변수와 다리의 길이를 입력받은 횟수만큼 리스트에 저장
6+
while bridge: #2. 다리의 길이가 0이 아닐때까지 반복
7+
time += 1 #3 time +1
8+
bridge.pop(0) #4.다리의 첫번째 원소 제거
9+
if truck: #5.bridge리스트를 추가하는건 truck리스트가 남아있을때까지
10+
if sum(bridge) + truck[0] <= l: #6기존 다리의 원소의 합 + 가장 왼쪽의 트럭'이 다리의 최대하중과 같거나 작다면.
11+
bridge.append(truck.pop(0))
12+
else: #7. 다리에 트럭이 있지만 다리에 올리지 못할 경우 다리 공간 유지하기 위해 0을 삽입
13+
bridge.append(0)
14+
print(time)

Hongjoo/백준/평범한배낭.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
"""
2+
N :물건 개수 , K : 제한 무게
3+
W , V : 개별 물건 무게 , 가지
4+
goal: max V
5+
6+
6 4 3 5
7+
13 8 6 12
8+
9+
-> 13/6 ,8/4 , 6/3 , 5/2
10+
goal : 낮은 무게부터 넣기
11+
[[3, 6], [4, 8], [5, 12], [6, 13]]
12+
1. sum(W) <= K인 조합 찾기
13+
2. w확인?
14+
"""
15+
#1. 변수 입력 받기
16+
import sys
17+
objects = list()
18+
N , K = map(int,sys.stdin.readline().split() )
19+
for i in range(N) :
20+
W , V = map(int,sys.stdin.readline().split() )
21+
objects.append([W,V])
22+
23+
# 가벼운 순으로 나열
24+
objects = sorted(objects)
25+
# print(objects)
26+
bags = list()
27+
#2. two point
28+
# start + window
29+
# for start in range(len(objects)) :
30+
# for end in range(1,len(objects)) : # end point
31+
start = 0 ; end= 1
32+
max_values = 0
33+
# 물건 1개의 무게 < target weight
34+
35+
while start < N and start < end and objects[end-1][0] <= K :
36+
37+
Subset = objects[start : end] # length = start -end
38+
currnet_weight = 0 ; current_values = 0
39+
# print(Subset)
40+
41+
for w,v in Subset :
42+
currnet_weight += w
43+
current_values += v
44+
45+
if currnet_weight <= K :# K 보다 현재 배낭 무게가 가벼우면 업데이트 진행
46+
max_values = max(max_values , current_values)
47+
end += 1
48+
elif currnet_weight <= K or end > N:# current_weight > k 이거나 end == N 이면 초기화
49+
current_values = 0
50+
start += 1
51+
end = start +1
52+
# print("end",end )
53+
# if end > N:
54+
# start += 1
55+
# end = start +1
56+
# # print(f"update { max_values}")
57+
print(max_values)
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))

0 commit comments

Comments
 (0)