practivceAlgorithm/백준 379

[백준][Python][삼성 2021 하반기 코딩테스트] 23288 주사위 굴리기2

주사위 굴리기 1이랑 비슷합니다. 주사위 좌표이동, 방향에 따른 회전, 위치에 따른 좌표 값 * cnt 만큼 최종합에 더해줌. 주사위 밑면과 지도값 비교에 따라 방향성 수정 위의 4가지 로직으로 이루어져 있습니다. 사실 새로운 지도 배열을 만든 후 거기에 미리 위치마다 더해야 하는 값을 미리 연산해 두면 같은 위치마다 bfs를 돌지 않아도 되지만 통과됐으니 생략.. 아래가 직관적인 로직이라고 생각합니다. import sys input = sys.stdin.readline from collections import deque def rotate_dice(d): if d == 0: dice['top'], dice['left'], dice['bottom'], dice['right'] = dice['left']..

[백준][Python] 1976 여행가자

분리집합 문제. union-find로 묶고 다른게 있으면 No 한집단이면 YES import sys input = sys.stdin.readline def union(x, y): x = find(x) y = find(y) if x > y: x, y = y, x parents[y] = x def find(x): if parents[x] == x: return x parents[x] = find(parents[x]) return parents[x] N = int(input()) M = int(input()) edges = [list(map(int, input().split())) for _ in range(N)] plan = list(map(lambda x: int(x) - 1, input().split()..

[백준][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..

[백준][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..