Skip to content

Commit f1b6448

Browse files
authored
찬민 책 구현 숙제 (#70)
* 찬민 백준 숙제 * 찬민 구현숙제 * 찬민 코드
1 parent ee860fd commit f1b6448

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+366
-0
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# 결국 그냥 미로찾기 문제에서 기본 비용은 100원 처리, 코너가 발생할때마다 500원 추가로 처리하면됀다
2+
from collections import deque
3+
4+
board = [[0, 0, 1, 0, 1, 1, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 1, 1, 0, 1], [1, 0, 0, 0, 0, 1, 1, 0, 1, 0], [0, 0, 0, 0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 1, 0, 1, 0, 1, 1], [0, 0, 1, 0, 1, 1, 0, 1, 0, 1], [0, 1, 0, 0, 1, 0, 0, 0, 1, 0], [1, 0, 0, 1, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1, 0, 1, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0, 1, 0]]
5+
6+
q = deque()
7+
dx, dy = [-1, 1, 0, 0], [0, 0, -1, 1] #상하좌우
8+
INF = 1000000000
9+
10+
def solution(board):
11+
answer = 0
12+
size = len(board)
13+
dp = [[INF] * size for _ in range(size)]
14+
visited = [[0] * size for _ in range(size)]
15+
visited[0][0] = 1
16+
if board[0][1] == 0:
17+
q.append((0, 0, 0, 1))
18+
while q:
19+
20+
x, y, count, dir = q.popleft() #dir은 진행방향 1 = 가로, -1 = 세로
21+
# if x == size - 1 and y == size - 1:
22+
# break
23+
24+
for i in range(4):
25+
nx = x + dx[i]
26+
ny = y + dy[i]
27+
if 0 <= nx < size and 0 <= ny < size and board[nx][ny] == 0:
28+
if dp[nx][ny] > count + 6:
29+
30+
if dir == 1 and i % 4 < 2: # 진행방향이 가로고, 다음 움직일 곳이 세로면
31+
dp[nx][ny] = min(dp[nx][ny], count + 6)
32+
q.append((nx, ny, count + 6, -1))
33+
elif dir == -1 and i % 4 > 1: # 진행방향이 세로고, 다음 움직일 곳이 가로면
34+
dp[nx][ny] = min(dp[nx][ny], count + 6)
35+
q.append((nx, ny, count + 6, 1))
36+
37+
if dp[nx][ny] > count + 1:
38+
if dir == 1 and i % 4 > 1: # 진행방향이 가로고, 다음 움직일 곳도 가로면
39+
dp[nx][ny] = min(dp[nx][ny], count + 1)
40+
q.append((nx, ny, count + 1, 1))
41+
elif dir == -1 and i % 4 < 2: # 진행방향이 세로고, 다음 움직일 곳이 세로면
42+
dp[nx][ny] = min(dp[nx][ny], count + 1)
43+
q.append((nx, ny, count + 1, -1))
44+
45+
46+
answer = dp[size - 1][size - 1] * 100
47+
48+
if board[1][0] == 0:
49+
q.append((0, 0, 0, -1))
50+
visited = [[INF] * size for _ in range(size)]
51+
visited[0][0] = 1
52+
dp = [[INF] * size for _ in range(size)]
53+
while q:
54+
55+
x, y, count, dir = q.popleft() # dir은 진행방향 1 = 가로, -1 = 세로
56+
# if x == size - 1 and y == size - 1:
57+
# break
58+
59+
for i in range(4):
60+
nx = x + dx[i]
61+
ny = y + dy[i]
62+
if 0 <= nx < size and 0 <= ny < size and board[nx][ny] == 0:
63+
if dp[nx][ny] > count + 6:
64+
65+
if dir == 1 and i % 4 < 2: # 진행방향이 가로고, 다음 움직일 곳이 세로면
66+
dp[nx][ny] = min(dp[nx][ny], count + 6)
67+
q.append((nx, ny, count + 6, -1))
68+
elif dir == -1 and i % 4 > 1: # 진행방향이 세로고, 다음 움직일 곳이 가로면
69+
dp[nx][ny] = min(dp[nx][ny], count + 6)
70+
q.append((nx, ny, count + 6, 1))
71+
72+
if dp[nx][ny] > count + 1:
73+
if dir == 1 and i % 4 > 1: # 진행방향이 가로고, 다음 움직일 곳도 가로면
74+
dp[nx][ny] = min(dp[nx][ny], count + 1)
75+
q.append((nx, ny, count + 1, 1))
76+
elif dir == -1 and i % 4 < 2: # 진행방향이 세로고, 다음 움직일 곳이 세로면
77+
dp[nx][ny] = min(dp[nx][ny], count + 1)
78+
q.append((nx, ny, count + 1, -1))
79+
80+
answer = min(answer, dp[size-1][size-1] * 100)
81+
82+
return answer
83+
84+
print(solution(board))
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
def solution(gems):
2+
answer = []
3+
4+
bosuck = []
5+
6+
for i in gems:
7+
if i not in bosuck:
8+
bosuck.append(i)
9+
10+
gems_count = len(gems)
11+
bosuck_count = len(bosuck)
12+
13+
print(gems_count)
14+
15+
switch = ([0] * bosuck_count for _ in range(gems_count))
16+
17+
for i in range(gems_count):
18+
if gems[i] in bosuck:
19+
for j in range(bosuck_count):
20+
if gems[i] == bosuck[j]:
21+
switch[i][j] = 1
22+
23+
print(switch)
24+
25+
26+
27+
return answer
28+
29+
'''
30+
[1] [0] [0] [0]
31+
[0] [1] [0] [0]
32+
[0] [0] [1] [0]
33+
[0] [0] [0] [1]
34+
[0] [0] [1] [0]
35+
[0] [0] [0] [0]
36+
[0] [0] [0] [0]
37+
[0] [0] [0] [0]
38+
39+
40+
'''
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# n가지 연산문자의 우선순위 재정의
2+
# 무조건 n가지 우선순위가 있어야한다
3+
# 음수는 절댓값으로 바꾸어 양수로 제출
4+
5+
def solution(expression):
6+
answer = 0
7+
8+
arr = '' #연산자 저장하는곳
9+
arr2 = ''
10+
num = []
11+
12+
for i in range(len(expression)):
13+
if expression[i] == '+' or expression[i] == '-' or expression[i] == '*':
14+
#arr.append[i]
15+
arr += expression[i]
16+
#expression[i] = 0
17+
print(expression)
18+
# expression.replace('+', '.')
19+
# expression.replace('-', '.')
20+
# expression.replace('*', '.')
21+
table = str.maketrans('+-*', '...') #씨발련
22+
expression.translate(table)
23+
24+
print(expression)
25+
26+
arr2 = (expression.split('.'))
27+
28+
print(arr2)
29+
30+
return answer
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# 2, 5, 8, 0 의 경우 가장 최근의 왼손 오른손 위치 따지기 + 주손 따지기
2+
3+
def solution(numbers, hand):
4+
5+
answer = ''
6+
left_cur = 0 # 양손의 위치 | 1, 4, 7, * 순으로 3, 2, 1, 0 에 대응한다
7+
left_hor = 1 # hor 값은 가로로 1, 2, 3 번째 줄 중 값중 하나
8+
9+
right_cur = 0
10+
right_hor = 3
11+
12+
mid_cur = 0
13+
mid_hor = 2
14+
15+
16+
for i in numbers:
17+
if i == 1 or i == 4 or i == 7 or i == '*':
18+
#print(left_cur, left_hor, right_cur, right_hor, mid_cur, mid_hor)
19+
answer += 'L'
20+
if i == 1:
21+
left_cur = 3
22+
if i == 4:
23+
left_cur = 2
24+
if i == 7:
25+
left_cur = 1
26+
if i == '*':
27+
left_cur = 0
28+
left_hor = 1
29+
30+
if i == 3 or i == 6 or i == 9 or i == '#':
31+
#print(left_cur, left_hor, right_cur, right_hor, mid_cur, mid_hor)
32+
answer += 'R'
33+
if i == 3:
34+
right_cur = 3
35+
if i == 6:
36+
right_cur = 2
37+
if i == 9:
38+
right_cur = 1
39+
if i == '#':
40+
right_cur = 0
41+
right_hor = 3
42+
43+
if i == 2 or i == 5 or i == 8 or i == 0:
44+
#print(left_cur, left_hor, right_cur, right_hor, mid_cur, mid_hor)
45+
if i == 2:
46+
mid_cur = 3
47+
if i == 5:
48+
mid_cur = 2
49+
if i == 8:
50+
mid_cur = 1
51+
if i == 0:
52+
mid_cur = 0
53+
mid_hor = 2
54+
55+
left_d = abs(mid_cur - left_cur) + (mid_hor - left_hor)
56+
right_d = abs(mid_cur - right_cur) + (right_hor - mid_hor) #abs가 절댓값이였나?
57+
58+
if left_d < right_d:
59+
answer += 'L'
60+
left_cur = mid_cur
61+
left_hor = 2
62+
elif left_d > right_d:
63+
answer += 'R'
64+
right_cur = mid_cur
65+
right_hor = 2
66+
else:
67+
if hand == 'left':
68+
answer += 'L'
69+
left_cur = mid_cur
70+
left_hor = 2
71+
else:
72+
answer += 'R'
73+
right_cur = mid_cur
74+
right_hor = 2
75+
76+
return answer
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
def solution(bridge_length, weight, truck_weights):
2+
3+
answer = 0
4+
5+
6+
7+
return answer
8+
9+
'''
10+
트럭 무게를 정렬할 필요는 없고
11+
그냥 순서대로
12+
'''
13+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
def solution(citations):
2+
answer = 0
3+
count = 0
4+
length = len(citations)
5+
citations.sort()
6+
7+
# print(citations[-4])
8+
9+
for i in range(1, length):
10+
if citations[-i] > i:
11+
answer = i
12+
13+
return answer
14+
15+
16+
# 끝에서 N번째 수가 N보다 큰가? 에 대한 질문
17+
18+
'''
19+
20+
0 1 3 3 5 6
21+
22+
1 2 2 3 3 4 4 4 5 6 7 9
23+
24+
'''
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
def solution(array, commands):
2+
arr = []
3+
answer = []
4+
example = len(commands)
5+
6+
for i in range(example):
7+
start = commands[i][0]
8+
end = commands[i][1]
9+
count = commands[i][2]
10+
11+
arr = array[start-1:end]
12+
arr.sort()
13+
14+
#print(arr)
15+
16+
answer.append(arr[count-1])
17+
18+
return answer
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
def solution(numbers):
2+
3+
answer = ''
4+
count = 0
5+
for i in range(len(numbers)):
6+
count += len(str(numbers[i])) # i번째 숫자의 자리수를 더해줘서 총 자리수 구하기
7+
8+
9+
10+
return answer
11+
12+
9
13+
---------
14+
15+
7.51
16+
17+
7.53
18+
19+
753
20+
755
21+
22+
7.92
23+
24+
75 / 10 = 7.55
25+
26+
7 7.77
27+
28+
7 7.77
29+
30+
8
31+
32+
9
File renamed without changes.

0 commit comments

Comments
 (0)