From fb2a3f78692470f9b40fdc12ac144efa9c4be642 Mon Sep 17 00:00:00 2001 From: bsyzch Date: Tue, 11 May 2021 02:55:26 +0900 Subject: [PATCH] =?UTF-8?q?=EC=A3=BC=EB=A7=90=EC=BD=94=ED=85=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\352\267\270\353\236\230\353\260\2151.py" | 36 +++++++++++++ ...4\352\267\270\353\236\230\353\260\2152.py" | 54 +++++++++++++++++++ ...4\352\267\270\353\236\230\353\260\2154.py" | 54 +++++++++++++++++++ ...4\352\267\270\353\236\230\353\260\2151.py" | 29 ++++++++++ ...4\352\267\270\353\236\230\353\260\2152.py" | 35 ++++++++++++ ...4\352\267\270\353\236\230\353\260\2153.py" | 0 6 files changed, 208 insertions(+) create mode 100644 "cmkim/2021 \354\271\264\354\271\264\354\230\244 \354\235\270\355\204\264\354\211\275/\355\224\204\353\241\234\352\267\270\353\236\230\353\260\2151.py" create mode 100644 "cmkim/2021 \354\271\264\354\271\264\354\230\244 \354\235\270\355\204\264\354\211\275/\355\224\204\353\241\234\352\267\270\353\236\230\353\260\2152.py" create mode 100644 "cmkim/2021 \354\271\264\354\271\264\354\230\244 \354\235\270\355\204\264\354\211\275/\355\224\204\353\241\234\352\267\270\353\236\230\353\260\2154.py" create mode 100644 "cmkim/2021 \355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244 \354\215\250\353\250\270\354\275\224\353\224\251/\355\224\204\353\241\234\352\267\270\353\236\230\353\260\2151.py" create mode 100644 "cmkim/2021 \355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244 \354\215\250\353\250\270\354\275\224\353\224\251/\355\224\204\353\241\234\352\267\270\353\236\230\353\260\2152.py" create mode 100644 "cmkim/2021 \355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244 \354\215\250\353\250\270\354\275\224\353\224\251/\355\224\204\353\241\234\352\267\270\353\236\230\353\260\2153.py" diff --git "a/cmkim/2021 \354\271\264\354\271\264\354\230\244 \354\235\270\355\204\264\354\211\275/\355\224\204\353\241\234\352\267\270\353\236\230\353\260\2151.py" "b/cmkim/2021 \354\271\264\354\271\264\354\230\244 \354\235\270\355\204\264\354\211\275/\355\224\204\353\241\234\352\267\270\353\236\230\353\260\2151.py" new file mode 100644 index 0000000..751ad9e --- /dev/null +++ "b/cmkim/2021 \354\271\264\354\271\264\354\230\244 \354\235\270\355\204\264\354\211\275/\355\224\204\353\241\234\352\267\270\353\236\230\353\260\2151.py" @@ -0,0 +1,36 @@ +num = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'] + +def solution(s): + answer = 0 + count = 0 + arr = [] + i = 0 + while i < len(s): + #print('i = ', i) + + if s[i].isdigit(): + arr.append(int(s[i])) + + else: + j = 0 + #print('i = ', i) + # print(s[i:]) + while j < 10: + if num[j] in s[i:i+5]: + #print('num[j] =', num[j]) + arr.append(j) + i += len(num[j]) - 1 + break + j += 1 + i += 1 + + #print(arr) + answer = int("".join(map(str, arr))) + #print('+'.join(arr)) + #answer = int("".join(arr)) + print(answer) + return answer + +#solution("one4seveneight") +solution('1zerotwozero3') + diff --git "a/cmkim/2021 \354\271\264\354\271\264\354\230\244 \354\235\270\355\204\264\354\211\275/\355\224\204\353\241\234\352\267\270\353\236\230\353\260\2152.py" "b/cmkim/2021 \354\271\264\354\271\264\354\230\244 \354\235\270\355\204\264\354\211\275/\355\224\204\353\241\234\352\267\270\353\236\230\353\260\2152.py" new file mode 100644 index 0000000..c899df6 --- /dev/null +++ "b/cmkim/2021 \354\271\264\354\271\264\354\230\244 \354\235\270\355\204\264\354\211\275/\355\224\204\353\241\234\352\267\270\353\236\230\353\260\2152.py" @@ -0,0 +1,54 @@ +from collections import deque + +def solution(places): + answer = [] + + for i in range(5): + flag = 1 + p_list = [] + #p_ad_list = [] + q = deque() + + for x in range(5): + for y in range(5): + if places[i][x][y] == 'P': + p_list.append((x, y)) + + for a in range(len(p_list)): + for b in range(a+1, len(p_list)): + if abs(p_list[a][0] - p_list[b][0]) + abs(p_list[a][1] - p_list[b][1]) < 3: + q.append((p_list[a][0], p_list[a][1], p_list[b][0], p_list[b][1])) + #p_ad_list.append((p_list[a][0], p_list[a][1], p_list[b][0], p_list[b][1])) + #print('adjacent', p_list[a][0], p_list[a][1], p_list[b][0], p_list[b][1]) + +#2칸 아래, +#2칸 우측 +#1칸 좌측, 1칸 아래 +#1칸 우측, 1칸 아래 + + while q: + x1, y1, x2, y2 = q.popleft() + if x1 + 2 == x2: + if places[i][x1 + 1][y1] == 'O': + flag -= 1 + elif y1 + 2 == y2: + if places[i][x1][y1+1] == 'O': + flag -= 1 + elif y1 - 1 == y2 and x1 + 1 == x2: #왼쪽아래 + if places[i][x1][y2] == 'O' or places[i][x2][y1] == 'O': + flag -= 1 + elif y1 + 1 == y2 and x1 + 1 == x2: + if places[i][x1][y2] == 'O' or places[i][x2][y1] == 'O': + flag -= 1 + elif x1 + 1 == x2 or y1 + 1 == y2: + flag -= 1 + + + if flag > 0: + answer.append(1) + else: + answer.append(0) + + return answer + +print(solution([["POOOP", "OXXOX", "OPXPX", "OOXOX", "POXXP"], ["POOPX", "OXPXP", "PXXXO", "OXXXO", "OOOPP"], ["PXOPX", "OXOXP", "OXPXX", "OXXXP", "POOXX"], ["OOOXX", "XOOOX", "OOOXX", "OXOOX", "OOOOO"], ["PXPXP", "XPXPX", "PXPXP", "XPXPX", "PXPXP"]])) \ No newline at end of file diff --git "a/cmkim/2021 \354\271\264\354\271\264\354\230\244 \354\235\270\355\204\264\354\211\275/\355\224\204\353\241\234\352\267\270\353\236\230\353\260\2154.py" "b/cmkim/2021 \354\271\264\354\271\264\354\230\244 \354\235\270\355\204\264\354\211\275/\355\224\204\353\241\234\352\267\270\353\236\230\353\260\2154.py" new file mode 100644 index 0000000..32b6bc8 --- /dev/null +++ "b/cmkim/2021 \354\271\264\354\271\264\354\230\244 \354\235\270\355\204\264\354\211\275/\355\224\204\353\241\234\352\267\270\353\236\230\353\260\2154.py" @@ -0,0 +1,54 @@ +from collections import deque + +#INF = 1000000000 + + +def solution(n, start, end, roads, traps): + visited = [[0] * (n + 1) for _ in range(n+1)] + answer = 1000000 + while q: + #print('roads = ', roads) + start, roads, traps, cost = q.popleft() + + if start == end: + answer = min(answer, cost) + continue + + for a, b, c in roads: # 출발, 도착, 비용 + if start == a : # 이동할 다음노드가 있으면 이동 + if b not in traps: #다음노드가 정상적으로 이동할 노드면 + if not visited[a][b]: + visited[a][b] = 1 + q.append((b, roads, traps, cost+c)) + continue + else: # 다음노드가 함정노드면 + if not visited[a][b]: + visited[a][b] = 1 + + for i in range(len(roads)): + if roads[i][0] == b or roads[i][1] == b: + temp = roads[i][0] + roads[i][0] = roads[i][1] + roads[i][1] = temp + q.append((b, roads, traps, cost+c)) + + + + print(answer) + return answer +q = deque() + +# n = 3 +# start = 1 +# end = 3 +# roads = [[1, 2, 2], [3, 2, 3]] +# traps = [2] + +n = 4 +start = 1 +end = 4 +roads = [[1, 2, 1], [3, 2, 1], [2, 4, 1]] +traps = [2, 3] + +q.append((start, roads, traps, 0)) #마지막은 cost +solution(n, start, end, roads, traps) \ No newline at end of file diff --git "a/cmkim/2021 \355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244 \354\215\250\353\250\270\354\275\224\353\224\251/\355\224\204\353\241\234\352\267\270\353\236\230\353\260\2151.py" "b/cmkim/2021 \355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244 \354\215\250\353\250\270\354\275\224\353\224\251/\355\224\204\353\241\234\352\267\270\353\236\230\353\260\2151.py" new file mode 100644 index 0000000..ee69684 --- /dev/null +++ "b/cmkim/2021 \355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244 \354\215\250\353\250\270\354\275\224\353\224\251/\355\224\204\353\241\234\352\267\270\353\236\230\353\260\2151.py" @@ -0,0 +1,29 @@ +import sys + + +# from collections import deque + + +def solution(code, day, data): + answer = [] + q = [] + + for i in data: + arr = i.split(' ') + time = [] + if code in arr[1]: + if day in arr[2]: + time.append(int(arr[2][5:13])) + time.append(int(arr[2][13:15])) + + num = arr[0].split('=') + # answer.append(int(num[1])) + price = int(num[1]) + q.append((time[1], time[0], price)) + + q.sort() + + for i in range(len(q)): + answer.append(q[i][2]) + + return answer \ No newline at end of file diff --git "a/cmkim/2021 \355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244 \354\215\250\353\250\270\354\275\224\353\224\251/\355\224\204\353\241\234\352\267\270\353\236\230\353\260\2152.py" "b/cmkim/2021 \355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244 \354\215\250\353\250\270\354\275\224\353\224\251/\355\224\204\353\241\234\352\267\270\353\236\230\353\260\2152.py" new file mode 100644 index 0000000..5f1c6fc --- /dev/null +++ "b/cmkim/2021 \355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244 \354\215\250\353\250\270\354\275\224\353\224\251/\355\224\204\353\241\234\352\267\270\353\236\230\353\260\2152.py" @@ -0,0 +1,35 @@ +from collections import deque + + +def solution(t, r): + q = [] + wait = [] + answer = [] + flag = 0 + for j in range(len(t)): + q.append((j, int(t[j]), int(r[j]))) # id, 나갈시간, 우선순위 + + for i in range(10000): + for j in range(len(q)): + if i == q[j][1]: + wait.append((q[j][0], q[j][2])) + + index = 6 + for k in range(len(wait)): + index = min(index, wait[k][1]) + + #print(wait) + for k in range(len(wait)): + if wait[k][1] == index: + pop_id = k + answer.append(wait[k][0]) + wait.pop(pop_id) + break + + flag = 0 + print(answer) + + return answer +t = [0,1,3,0] +r = [0,1,2,3] +solution(t, r) \ No newline at end of file diff --git "a/cmkim/2021 \355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244 \354\215\250\353\250\270\354\275\224\353\224\251/\355\224\204\353\241\234\352\267\270\353\236\230\353\260\2153.py" "b/cmkim/2021 \355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244 \354\215\250\353\250\270\354\275\224\353\224\251/\355\224\204\353\241\234\352\267\270\353\236\230\353\260\2153.py" new file mode 100644 index 0000000..e69de29