From fe50df76b38997698af01e8fb29929caced15b39 Mon Sep 17 00:00:00 2001 From: bsyzch Date: Wed, 19 May 2021 11:00:20 +0900 Subject: [PATCH 1/2] =?UTF-8?q?=EC=B0=AC=EB=AF=BC=20=EC=B1=85=EC=88=99?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...60\353\212\245\352\260\234\353\260\234.py" | 0 ...0\353\212\224 \355\212\270\353\237\255.py" | 20 +++- .../\353\261\200_327p.py" | 91 +++++++++++++++++++ ...\202\250 \353\260\260\353\213\254_332p.py" | 41 +++++++++ 4 files changed, 147 insertions(+), 5 deletions(-) create mode 100644 "cmkim/Programmers/\354\212\244\355\203\235_\355\201\220/\352\270\260\353\212\245\352\260\234\353\260\234.py" create mode 100644 "cmkim/\354\235\264\352\262\203\354\235\264 \354\267\250\354\227\205\354\235\204 \354\234\204\355\225\234 \354\275\224\353\224\251 \355\205\214\354\212\244\355\212\270\353\213\244/\353\261\200_327p.py" create mode 100644 "cmkim/\354\235\264\352\262\203\354\235\264 \354\267\250\354\227\205\354\235\204 \354\234\204\355\225\234 \354\275\224\353\224\251 \355\205\214\354\212\244\355\212\270\353\213\244/\354\271\230\355\202\250 \353\260\260\353\213\254_332p.py" diff --git "a/cmkim/Programmers/\354\212\244\355\203\235_\355\201\220/\352\270\260\353\212\245\352\260\234\353\260\234.py" "b/cmkim/Programmers/\354\212\244\355\203\235_\355\201\220/\352\270\260\353\212\245\352\260\234\353\260\234.py" new file mode 100644 index 0000000..e69de29 diff --git "a/cmkim/Programmers/\354\212\244\355\203\235_\355\201\220/\353\213\244\353\246\254\353\245\274 \354\247\200\353\202\230\353\212\224 \355\212\270\353\237\255.py" "b/cmkim/Programmers/\354\212\244\355\203\235_\355\201\220/\353\213\244\353\246\254\353\245\274 \354\247\200\353\202\230\353\212\224 \355\212\270\353\237\255.py" index 2b7019c..450398c 100644 --- "a/cmkim/Programmers/\354\212\244\355\203\235_\355\201\220/\353\213\244\353\246\254\353\245\274 \354\247\200\353\202\230\353\212\224 \355\212\270\353\237\255.py" +++ "b/cmkim/Programmers/\354\212\244\355\203\235_\355\201\220/\353\213\244\353\246\254\353\245\274 \354\247\200\353\202\230\353\212\224 \355\212\270\353\237\255.py" @@ -1,13 +1,23 @@ def solution(bridge_length, weight, truck_weights): + time = 0 + on_bridge = [] + on_time = [] - answer = 0 + while(truck_weights or on_bridge) : + time += 1 + if(on_time) : + if(on_time[0] + bridge_length == time) : + on_bridge.pop(0) + on_time.pop(0) + if(truck_weights) : + if(sum(on_bridge) + truck_weights[0] <= weight) : + on_bridge.append(truck_weights.pop(0)) + on_time.append(time) - - return answer - + return time ''' 트럭 무게를 정렬할 필요는 없고 그냥 순서대로 +아 무조건 정해진 순서대로 가야한다.. ''' - diff --git "a/cmkim/\354\235\264\352\262\203\354\235\264 \354\267\250\354\227\205\354\235\204 \354\234\204\355\225\234 \354\275\224\353\224\251 \355\205\214\354\212\244\355\212\270\353\213\244/\353\261\200_327p.py" "b/cmkim/\354\235\264\352\262\203\354\235\264 \354\267\250\354\227\205\354\235\204 \354\234\204\355\225\234 \354\275\224\353\224\251 \355\205\214\354\212\244\355\212\270\353\213\244/\353\261\200_327p.py" new file mode 100644 index 0000000..33ab7d3 --- /dev/null +++ "b/cmkim/\354\235\264\352\262\203\354\235\264 \354\267\250\354\227\205\354\235\204 \354\234\204\355\225\234 \354\275\224\353\224\251 \355\205\214\354\212\244\355\212\270\353\213\244/\353\261\200_327p.py" @@ -0,0 +1,91 @@ +n = int(input()) +k = int(input()) + +arr = [[0]*n for _ in range(n+1)] +order = [] +count = 0 +dir = 0 + +for i in range(k): + a, b = map(int, input().split()) + arr[a][b] = 1 + +l = int(input()) + +for i in range(l): + # x = int(input().split()) + # c = input() + x, c = input().split() + order.append((int(x), c)) + +# for i in range(n): +# print(arr[i]) +# print(order) +# order.pop() +#print(order) + +#오른쪽 볼때 좌, 우 회전 순서는 각각 우 상 좌 하 / 우 하 좌 상 +#왼쪽 '' 좌 하 우 상 / 좌 상 우 하 + +dx = [0, -1, 0, 1] #우 상 좌 하 +dy = [1, 0, -1, 0] + +x, y = 1, 1 +q = [(x, y)] + +while True: + count += 1 + + arr[x][y] = 2 + + + + nx = x + dx[dir] + ny = y + dy[dir] + + if 1 <= nx <= n and 1 <= ny <= n and arr[nx][ny] != 2: + if arr[nx][ny] == 0: + arr[nx][ny] = 2 + q.append((nx, ny)) + ex, ey = q.pop(0) + arr[ex][ey] = 0 + + elif arr[nx][ny] == 1: + arr[nx][ny] = 2 + q.append((nx, ny)) + + x, y = nx, ny + + else: + break + + if count == order[0][0]: + if order[0][1] == 'L': #왼쪽회전 + dir = (dir+1) % 4 + else: #오른쪽회전 + dir = (dir+3) % 4 + + order.pop() + +print(count) + + + + + + + + + + +''' +6 +3 +3 4 +2 5 +5 3 +3 +3 D +15 L +17 D +''' \ No newline at end of file diff --git "a/cmkim/\354\235\264\352\262\203\354\235\264 \354\267\250\354\227\205\354\235\204 \354\234\204\355\225\234 \354\275\224\353\224\251 \355\205\214\354\212\244\355\212\270\353\213\244/\354\271\230\355\202\250 \353\260\260\353\213\254_332p.py" "b/cmkim/\354\235\264\352\262\203\354\235\264 \354\267\250\354\227\205\354\235\204 \354\234\204\355\225\234 \354\275\224\353\224\251 \355\205\214\354\212\244\355\212\270\353\213\244/\354\271\230\355\202\250 \353\260\260\353\213\254_332p.py" new file mode 100644 index 0000000..1058b99 --- /dev/null +++ "b/cmkim/\354\235\264\352\262\203\354\235\264 \354\267\250\354\227\205\354\235\204 \354\234\204\355\225\234 \354\275\224\353\224\251 \355\205\214\354\212\244\355\212\270\353\213\244/\354\271\230\355\202\250 \353\260\260\353\213\254_332p.py" @@ -0,0 +1,41 @@ +from itertools import combinations +n, m = map(int, input().split()) + +arr = [] +chicken = [] +home = [] + +for i in range(n): + temp = list(map(int, input().split())) + for j in range(n): + if temp[j] == 1: + home.append((i, j)) + elif temp[j] == 2: + chicken.append((i, j)) + +m_chicken = list(combinations(chicken, m)) + +def get_sum(candidate): + result = 0 + for hx, hy in home: + temp = 1e9 + for cx, cy in candidate: + temp = min(temp, abs(hx - cx) + abs(hy - cy)) + result += temp + return result + +result = 1e9 +for i in m_chicken: + result = min(result, get_sum(i)) + + +print(result) + +''' +5 3 +0 0 1 0 0 +0 0 2 0 1 +0 1 2 0 0 +0 0 1 0 0 +0 0 0 0 2 +''' \ No newline at end of file From 388a60aa80cbd04f0c27984a8540c786f3de08bc Mon Sep 17 00:00:00 2001 From: bsyzch Date: Wed, 19 May 2021 13:25:35 +0900 Subject: [PATCH 2/2] =?UTF-8?q?=EC=B0=AC=EB=AF=BC=20=EB=B0=B1=EC=A4=80?= =?UTF-8?q?=EC=88=99=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\353\260\261\354\244\200_1939.py" | 24 ++++++++++++++++ .../\353\260\261\354\244\200_5972.py" | 28 +++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 "cmkim/BaekJoon/\353\260\261\354\244\200_1939.py" create mode 100644 "cmkim/BaekJoon/\353\260\261\354\244\200_5972.py" diff --git "a/cmkim/BaekJoon/\353\260\261\354\244\200_1939.py" "b/cmkim/BaekJoon/\353\260\261\354\244\200_1939.py" new file mode 100644 index 0000000..f66a64c --- /dev/null +++ "b/cmkim/BaekJoon/\353\260\261\354\244\200_1939.py" @@ -0,0 +1,24 @@ +n, m = map(int, input().split()) + +arr = [[] for _ in range(n+1)] + +for i in range(m): + a, b, c = map(int, input().split()) + arr[a].append([b, c]) + arr[b].append([a, b]) + +for i in range(1, n+1): + print(arr[i]) + +start, end = map(int, input().split()) + + +# 플로이드 워셜 반대로? +# for m in range(1, n+1): +# for s in range(1, n+1): +# for e in range(1, n+1): +# if d[s][e] > d[s][m] + d[m][e]: +# d[s][e] = d[s][m] + d[m][e] + + +#print(d) diff --git "a/cmkim/BaekJoon/\353\260\261\354\244\200_5972.py" "b/cmkim/BaekJoon/\353\260\261\354\244\200_5972.py" new file mode 100644 index 0000000..8d2d8d4 --- /dev/null +++ "b/cmkim/BaekJoon/\353\260\261\354\244\200_5972.py" @@ -0,0 +1,28 @@ +import sys +import heapq +INF = 1e9 +n, m = map(int, input().split()) +arr = [[] * (n+1) for _ in range(n+1)] +dis = [INF] * (n+1) + +for _ in range(m): + a, b, c = map(int, input().split()) + arr[a].append((b, c)) + arr[b].append((a, c)) + +def dijkstra(start): + q = [] + heapq.heappush(q, (0, start)) #비용, 출발점 + dis[start] = 0 + while q: + d, now = heapq.heappop(q) + if dis[now] < d: + continue + for v, w in arr[now]: # 가려는 곳에대한 위치, 비용 + cost = d + w + if cost < dis[v]: + dis[v] = cost + heapq.heappush(q, (cost, v)) + +dijkstra(1) +print(dis[n]) \ No newline at end of file