본문 바로가기

Algorithm/BOJ133

[백준] 19236번 - 청소년 상어 (파이썬) # 청소년 상어 import copy dx = [0, -1, -1, 0, 1, 1, 1, 0, -1] dy = [0, 0, -1, -1, -1, 0, 1, 1, 1] arr = [] fish = [[0]] for k in range(4): temp = list(map(int, input().split())) arr.append([temp[i] for i in range(0, len(temp), 2)]) for i in range(0, len(temp), 2): fish.append([temp[i], [k, i//2, temp[i+1]]]) def fish_move(arr, fish): for i, temp in enumerate(fish): if i != 0: x, info = temp if not ea.. 2022. 3. 12.
[백준] 10282번 - 해킹 (파이썬) # 해킹 import heapq import sys input = sys.stdin.readline def hacking(n, start): dist = [sys.maxsize] * (n+1) dist[start] = 0 q = [] heapq.heappush(q, (0, start)) while q: time, computer = heapq.heappop(q) for ntime, ncom in arr[computer]: total = time + ntime if dist[ncom] > total: dist[ncom] = total heapq.heappush(q, (total, ncom)) result_time = 0 result_com = 0 for x in dist: if x != sys.maxsiz.. 2022. 3. 11.
[백준] 2473번 - 세 용액 (파이썬) # 세 용액 import sys input = sys.stdin.readline N = int(input()) arr = list(map(int, input().split())) arr.sort() result = sys.maxsize three = [] for i in range(N-2): left = i+1 right = N-1 while left 0: right -= 1 else: break print(*th.. 2022. 3. 10.
[백준] 2470번 - 두 용액 (파이썬) # 두 용액 import sys input = sys.stdin.readline N = int(input()) arr = list(map(int, input().split())) arr.sort() result = [] min_result = sys.maxsize sum = 0 left = 0 right = N-1 while left 0: right -= 1 else: break sum = 0 print(*result) 투포인터 1. 정.. 2022. 3. 10.
[백준] 2812번 - 크게 만들기 (파이썬) # 크게 만들기 N, K = map(int, input().split()) arr = list(map(int, input().strip())) result = [] for x in arr: if not result: result.append(x) continue while result and result[-1] < x and K != 0: K -= 1 result.pop() result.append(x) while K != 0: K -= 1 result.pop() print(*result, sep='') 자료구조(스택), 그리디 1. result 리스트를 정의하고 입력받은 값들을 하나씩 순회 - result 리스트가 비어 있다면 append하고 continue - result[-1]보다 현재 값이 더 크.. 2022. 3. 9.
[백준] 17822번 - 원판 돌리기 (파이썬) # 원판 돌리기 from collections import deque import sys intput = sys.stdin.readline N, M, T = map(int, input().split()) dx = [0, 1, 0, -1] dy = [1, 0, -1, 0] arr = [] for _ in range(N): arr.append(deque(map(int, input().split()))) order = [] for _ in range(T): order.append(list(map(int, input().split()))) def rolling(n, dir): for x in range(n, N+1, n): if dir == 0: temp = arr[x-1].pop() arr[x-1].appen.. 2022. 3. 8.
[백준] 2239번 - 스도쿠 (파이썬) # 스도쿠 import sys input = sys.stdin.readline N = 9 arr = [] empty = [] for i in range(N): arr.append(list(input().strip())) for j in range(N): if arr[i][j] == '0': empty.append((i, j)) def add_num(k): global isDone if k == len(empty): isDone = True return temp = check_available_num(empty[k][0], empty[k][1]) for x in temp: arr[empty[k][0]][empty[k][1]] = x add_num(k+1) if isDone: return arr[empty[.. 2022. 3. 5.