From d6c792c36589730dce86810b0d8d4a607f634adf Mon Sep 17 00:00:00 2001 From: minjungkim <97938489+pushedrumex@users.noreply.github.com> Date: Tue, 9 Jul 2024 13:48:20 +0900 Subject: [PATCH] 37_pushedrumex (#155) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * n+1 카드게임 * 교점에 별 만들기 * 귤 고르기 * 섬 연결하기 * n진법 뒤집기 --- ...64\353\223\234\352\262\214\354\236\204.py" | 47 +++++++++++++++++++ ...5 \353\222\244\354\247\221\352\270\260.py" | 11 +++++ ...4 \353\247\214\353\223\244\352\270\260.py" | 34 ++++++++++++++ ...4 \352\263\240\353\245\264\352\270\260.py" | 11 +++++ ...60\352\262\260\355\225\230\352\270\260.py" | 29 ++++++++++++ 5 files changed, 132 insertions(+) create mode 100644 "week-37/pushedrumex/n+1 \354\271\264\353\223\234\352\262\214\354\236\204.py" create mode 100644 "week-37/pushedrumex/n\354\247\204\353\262\225 \353\222\244\354\247\221\352\270\260.py" create mode 100644 "week-37/pushedrumex/\352\265\220\354\240\220\354\227\220 \353\263\204 \353\247\214\353\223\244\352\270\260.py" create mode 100644 "week-37/pushedrumex/\352\267\244 \352\263\240\353\245\264\352\270\260.py" create mode 100644 "week-37/pushedrumex/\354\204\254 \354\227\260\352\262\260\355\225\230\352\270\260.py" diff --git "a/week-37/pushedrumex/n+1 \354\271\264\353\223\234\352\262\214\354\236\204.py" "b/week-37/pushedrumex/n+1 \354\271\264\353\223\234\352\262\214\354\236\204.py" new file mode 100644 index 0000000..b59d526 --- /dev/null +++ "b/week-37/pushedrumex/n+1 \354\271\264\353\223\234\352\262\214\354\236\204.py" @@ -0,0 +1,47 @@ +from collections import deque + +INF = int(1e9) +# 일단 카드를 모두 갖고, 카드를 사용해야할 때 coin 지불 +def solution(coin, cards): + global my_cards, cost, n + + n = len(cards) + cards = deque(cards) + my_cards = [] + cost = [INF] * (n+1) + for _ in range(n//3): + card = cards.popleft() + my_cards.append(card) + cost[card] = 0 + + answer = 1 + while len(cards) > 0: + # 카드 두 장 뽑기 + for _ in range(2): + card = cards.popleft() + my_cards.append(card) + cost[card] = 1 + + _cost, _cards = find() + + if _cost > coin: + break + + coin -= _cost + for card in _cards: + my_cards.remove(card) + + answer += 1 + return answer + +# 가장 저렴한 비용으로 n+1이 되는 카드 찾기 +def find(): + _cost = INF + _cards = [] + for card in my_cards: + temp = cost[card] + cost[n+1-card] + if _cost > temp: + _cost = temp + _cards = [card, n+1-card] + + return (_cost, _cards) diff --git "a/week-37/pushedrumex/n\354\247\204\353\262\225 \353\222\244\354\247\221\352\270\260.py" "b/week-37/pushedrumex/n\354\247\204\353\262\225 \353\222\244\354\247\221\352\270\260.py" new file mode 100644 index 0000000..f03d2f1 --- /dev/null +++ "b/week-37/pushedrumex/n\354\247\204\353\262\225 \353\222\244\354\247\221\352\270\260.py" @@ -0,0 +1,11 @@ +def solution(n): + third = [] + while n > 0: + third.append(n%3) + n //= 3 + answer = 0 + m = 0 + for k in third[::-1]: + answer += k *(3**m) + m += 1 + return answer \ No newline at end of file diff --git "a/week-37/pushedrumex/\352\265\220\354\240\220\354\227\220 \353\263\204 \353\247\214\353\223\244\352\270\260.py" "b/week-37/pushedrumex/\352\265\220\354\240\220\354\227\220 \353\263\204 \353\247\214\353\223\244\352\270\260.py" new file mode 100644 index 0000000..f3c03bc --- /dev/null +++ "b/week-37/pushedrumex/\352\265\220\354\240\220\354\227\220 \353\263\204 \353\247\214\353\223\244\352\270\260.py" @@ -0,0 +1,34 @@ +INF = int(1e15) +def solution(line): + points = set() + min_x = INF + min_y = INF + max_x = -INF + max_y = -INF + N = len(line) + for i in range(N-1): + A, B, E = line[i] + for j in range(i+1, N): + C, D, F = line[j] + xc = B*F - E*D + yc = E*C - A*F + p = A*D - B*C + if p == 0: + continue + x = xc / p + y = yc / p + int_x = int(x) + int_y = int(y) + if x == int_x and y == int_y: + points.add((int_x, int_y)) + min_x, min_y = min(min_x, int_x), min(min_y, int_y) + max_x, max_y = max(max_x, int_x), max(max_y, int_y) + + result = [["."] * (abs(max_x-min_x)+1) for _ in range(abs(max_y-min_y)+1)] + for x, y in points: + result[y-min_y][x-min_x] = "*" + + answer = [] + for row in result: + answer.append("".join(row)) + return answer[::-1] \ No newline at end of file diff --git "a/week-37/pushedrumex/\352\267\244 \352\263\240\353\245\264\352\270\260.py" "b/week-37/pushedrumex/\352\267\244 \352\263\240\353\245\264\352\270\260.py" new file mode 100644 index 0000000..f26b26c --- /dev/null +++ "b/week-37/pushedrumex/\352\267\244 \352\263\240\353\245\264\352\270\260.py" @@ -0,0 +1,11 @@ +def solution(k, tangerine): + count = [0] * (10_000_000+1) + for t in tangerine: + count[t] += 1 + count.sort(reverse=True) + i = 0 + while k > 0: + k -= count[i] + i += 1 + + return i \ No newline at end of file diff --git "a/week-37/pushedrumex/\354\204\254 \354\227\260\352\262\260\355\225\230\352\270\260.py" "b/week-37/pushedrumex/\354\204\254 \354\227\260\352\262\260\355\225\230\352\270\260.py" new file mode 100644 index 0000000..59a5a07 --- /dev/null +++ "b/week-37/pushedrumex/\354\204\254 \354\227\260\352\262\260\355\225\230\352\270\260.py" @@ -0,0 +1,29 @@ +def find_parent(node): + if parent[node] != node: + parent[node] = find_parent(parent[node]) + return parent[node] + +def union(node1, node2): + parent1 = find_parent(node1) + parent2 = find_parent(node2) + if parent1 < parent2: + parent[parent2] = parent1 + else: + parent[parent1] = parent2 + +def solution(n, costs): + global parent + + parent = [0] * n + for i in range(n): + parent[i] = i + + answer = 0 + costs.sort(key = lambda x: x[2]) + + for node1, node2, cost in costs: + if find_parent(node1) != find_parent(node2): + union(node1, node2) + answer += cost + + return answer \ No newline at end of file