[백준][Python] 2776 암기왕 set을 사용한 checking import sys input = sys.stdin.readline for test in range(int(input())): N = int(input()) arr1 = set(input().split()) M = int(input()) for num in input().split(): print(1 if num in arr1 else 0) practivceAlgorithm/백준 2021.10.21
[programmers][Python] 2021 kakao blind 메뉴 리뉴얼 sets에 조합 출현 갯수 cnt ans_set에 2번이상이고 최고 많이 나온 comb 입력 answer에 ans_set에 들어간 comb만 추출 후 정렬 반환 from collections import defaultdict from itertools import combinations def solution(orders, course): answer = [] sets = defaultdict(int) for order in orders: order = sorted(list(order)) for num in course: for new_comb in combinations(order, num): sets[''.join(list(new_comb))] += 1 ans_set = {num: [] for num.. practivceAlgorithm/programmers 2021.10.20
[programmers][Python] 2021 kakao blind 신규아이디 추천 규칙에 따라 parsing def solution(new_id): answer = '' for char in new_id: if char.isalpha(): answer += char.lower() elif char == '.' and answer and answer[-1] != '.': answer += '.' elif char.isdigit() or char in '-_': answer += char if not answer: answer += 'a' elif len(answer) > 15: answer = answer[:15] if answer[-1] == '.': answer = answer[:-1] while len(answer) < 3: answer = answer + answer[-1] re.. practivceAlgorithm/programmers 2021.10.20
[백준][Python] 20168 골목대장 호석 그냥 다익스트라 한번으로는 안된다. 최대한계값을 정해주고 돌려야한다. 최대한계값은 이분탐색으로 찾는다., import heapq import sys input = sys.stdin.readline def dijkstra(mid): dist = [float('inf')] * (N + 1) dist[start] = 0 H = [(0, start)] while H: dist, cur_node = heapq.heappop(H) if dist[cur_node] mid: continue if dist[next_node] > dist + cost: dist[next_node] = dist + cos.. practivceAlgorithm/백준 2021.10.20
[백준][Python] 2469 사다리 타기 위에서 start배열 swap 아래서부터 받아온 last 배열 swap 후 비교해주며 *, - 더해주기 import sys input = sys.stdin.readline k, n = int(input()), int(input()) start = [] for i in range(k): start.append(chr(ord('A') + i)) last = list(input().rstrip()) ladder_game = [list(input().rstrip()) for _ in range(n)] flag = 0 for row in range(n): if flag: break for col in range(k - 1): if ladder_game[row][col] == '-': start[col], star.. practivceAlgorithm/백준 2021.10.20
[백준][Python] 2729 이진수 덧셈 파이썬의 int, bin 메서드를 사용해 풀이 import sys input = sys.stdin.readline for test in range(int(input())): a, b = map(lambda x: int(x, 2), input().split()) print(bin(a + b)[2:]) practivceAlgorithm/백준 2021.10.19
[백준][Python] 1987 알파뱃 상태공간 check에 같은 상태가 안오도록 가지치기. import sys input = sys.stdin.readline def bfs(x, y): q = set([(x, y, board[x][y])]) check[x][y] = board[x][y] answer = 1 while q: x, y, string = q.pop() for dx, dy in delta: nx, ny = x + dx, y + dy if 0 practivceAlgorithm/백준 2021.10.19
[백준][Python] 18115 카드 놓기 deque와 맨앞 요소만 책임지는 front배열을 두어 운용했습니다. import sys input = sys.stdin.readline from collections import deque N = int(input()) a = list(map(int, input().split()))[::-1] floor = [i for i in range(N, 1, -1)] front = [1] q = deque() for command in a[1:]: if command == 1: q.appendleft(front.pop()) front.append(floor.pop()) elif command == 2: q.appendleft(floor.pop()) else: q.append(floor.pop()) answer .. practivceAlgorithm/백준 2021.10.19
[백준][Python] 18429 근손실 global 변수 안쓰고 탑다운 방식으로 구현 import sys input = sys.stdin.readline def dfs(depth, weight): if depth == N: return 1 ret = 0 for i in range(N): next_weight = weight - K + a[i] if not check[i] and next_weight >= 500: check[i] = True ret += dfs(depth + 1, next_weight) check[i] = False return ret N, K = map(int, input().split()) a = list(map(int, input().split())) check = {i: False for i in range(N)} pr.. practivceAlgorithm/백준 2021.10.19
[백준][Python] 2164 카드2 deque로 구현했습니다. import sys input = sys.stdin.readline from collections import deque N = int(input()) q = deque([i for i in range(1, N + 1)]) while len(q) != 1: q.popleft() if len(q) == 1: break q.rotate(-1) print(q.pop()) practivceAlgorithm/백준 2021.10.19