본문 바로가기

분류 전체보기263

[백준] 15685번 - 드래곤 커브 (파이썬) # 드래곤 커브 import sys input = sys.stdin.readline T = int(input()) arr = [[False] * 101 for _ in range(101)] dx = [0, -1, 0, 1] dy = [1, 0, -1, 0] q = [] for _ in range(T): y, x, d, g = map(int, input().split()) q.append((x, y, d, g)) def dragon_curve(): for x, y, d, g in q: arr[x][y] = True dir = [d] for _ in range(g): for d in range(len(dir)-1, -1, -1): temp = (dir[d] + 1) % 4 dir.append(temp) fo.. 2022. 1. 26.
[백준] 14890번 - 경사로 (파이썬) # 경사로 import sys input = sys.stdin.readline N, L = map(int, input().split()) arr = [] for _ in range(N): arr.append(list(map(int, input().split()))) result = 0 def check(line): global result isOK = True isSlope = [False] * N for i in range(N-1): if line[i] == line[i+1]: continue elif abs(line[i] - line[i+1]) >= 2: isOK = False break elif abs(line[i] - line[i+1]) == 1: if slope_check(line, i, isS.. 2022. 1. 26.
[백준] 1655번 - 가운데를 말해요 (파이썬) # 가운데를 말해요 import sys import heapq input = sys.stdin.readline N = int(input()) left = [] right = [] for _ in range(N): if len(left) == len(right): heapq.heappush(left, -int(input())) else: heapq.heappush(right, int(input())) if len(left) != 0 and len(right) != 0 and -left[0] > right[0]: add_left = heapq.heappop(right) add_right = heapq.heappop(left) heapq.heappush(left, -add_left) heapq.heappush.. 2022. 1. 26.
[리액트(React)] 6. 리액트훅(Hook) - 기본편 본격적으로 훅을 공부해보자 우선 기본적인 것들만 먼저 공부를 하고 추후 필요할 때 다시 공부를 해야겠다. 시작하기 전에... 함수는 안에 정의된 모든 요소들은 호출이 될 때마다 재정의가 되는 것을 처음 정의만 하면 반복되지 않게 도와주는 것이 훅의 시작이다 1. useState - useState는 state를 기억해준다 useState(초기값)는 [state이름, state변경함수] 를 반환한다. state 변경시에는 state변경 함수를 이용해서 변경해줘야 한다. // components/greeting.jsx import React, {useState} from 'react'; function Greeting(props) { const [num, setNum] = useState(0) const g.. 2022. 1. 25.
[백준] 2573번 - 빙산 (파이썬) # 빙산 from collections import deque import sys input = sys.stdin.readline N, M = map(int, input().split()) arr = [] ice = [] melt = [] for i in range(N): arr.append(list(map(int, input().split()))) for j in range(M): if arr[i][j] != 0: ice.append((i, j)) dx = [0, 1, 0, -1] dy = [1, 0, -1, 0] def melt_check(): for x, y in ice: if arr[x][y] != 0: zero = 0 for k in range(4): nx = x + dx[k] ny = y + .. 2022. 1. 25.
[백준] 1238번 - 파티 (파이썬) # 파티 import sys import heapq input = sys.stdin.readline MAX = sys.maxsize N, M, X = map(int, input().split()) arr = [[] for _ in range(N+1)] for _ in range(M): a, b, cost = map(int, input().split()) arr[a].append((cost, b)) come = [MAX] * (N+1) go = [MAX] * (N+1) def go_dijkstra(x): q = [] heapq.heappush(q, (0, x)) go[x] = 0 while q: cost, node = heapq.heappop(q) for ncost, nnode in arr[node]: i.. 2022. 1. 25.
[백준] 12100번 - 2048(Easy) (파이썬) # 2048 (Easy) import copy import sys input = sys.stdin.readline N = int(input()) arr = [] for _ in range(N): arr.append(list(map(int, input().split()))) dir = [[0, 1], [1, 0], [0, -1], [-1, 0]] result = 0 def move_block(arr, n): set_result(arr) if n == 5: # 이동 끝 return for k in range(4): temp = copy.deepcopy(arr) combine_and_move(temp, k) move_block(temp, n+1) def combine_and_move(arr, k): is_co.. 2022. 1. 25.