본문 바로가기

분류 전체보기263

[백준] 2042번 - 구간 합 구하기 (파이썬) # 구간 합 구하기 import sys input = sys.stdin.readline N, M, K = map(int, input().split()) arr = [0] for _ in range(N): arr.append(int(input())) tree = [0] * (N+1) def update(i, diff): while i 0: result += tree[i] i -= (i & -i) return result def print_sum(start, end): print(fromOne_sum(end) - fromOne_sum(start-1)) for i, x in enumerate(arr): if i > 0: update(i, x) for _ in range(M+K): type, a, b = map.. 2022. 2. 12.
[백준] 16637번 - 괄호 추가하기 (파이썬) # 괄호 추가하기 import copy import sys input = sys.stdin.readline MAX = sys.maxsize N = int(input()) arr = input().strip() nums = [] op = [] for i, x in enumerate(arr): if i % 2 == 0: nums.append(x) else: op.append(x) def calculate(a, op, b): return str(eval(a+op+b)) def calculate_front(arr): result = arr[0] for i in range(1, len(arr)-1, 2): result = calculate(result, arr[i], arr[i+1]) return result d.. 2022. 2. 12.
[백준] 1700번 - 멀티탭 스케줄링 (파이썬) # 멀티탭 스케줄링 from asyncore import close_all import sys input = sys.stdin.readline N, K = map(int, input().split()) use = list(map(int, input().split())) plugs = [] result = 0 for i in range(K): # 이미 있다면 if use[i] in plugs: continue # 빈공간이 있다면 if len(plugs) != N: plugs.append(use[i]) continue # 가장 멀리 있는 플러그의 인덱스 far_one = 0 temp = 0 # 현재 꽂혀있는 플러그들 확인 for plug in plugs: # 앞으로 사용할 플러그에 없으면 if plug no.. 2022. 2. 12.
[백준] 2887번 - 행성 터널 (파이썬) # 행성 터널 import copy import heapq import sys input = sys.stdin.readline N = int(input()) planets = [] for i in range(N): x, y, z = map(int, input().split()) planets.append((x, y, z, i)) planets_x = copy.deepcopy(planets) planets_y = copy.deepcopy(planets) planets_z = copy.deepcopy(planets) planets_x.sort(key=lambda index: index[0]) planets_y.sort(key=lambda index: index[1]) planets_z.sort(key=lam.. 2022. 2. 12.
[JavaScript] 테트리스 웹 게임 만들기 (3) 블록 정의 및 렌더링 테트리스 웹 게임 만들기 (3) - 블록 정의 및 렌더링 1. 블록 정의 이제 블록의 모양을 지정할 차례이다. 정의하기 전에 좌표를 설정하기 위해서 블록들을 그렸다. 이후 아래와 같이 블록 객체에 각 블록의 이름을 지정해주고 블록의 위치인 2차원 배열을 할당해주었다. // js/block.js const blocks = { square: [ [ [0, 1], [0, 2], [1, 1], [1, 2], ], [ [0, 1], [0, 2], [1, 1], [1, 2], ], [ [0, 1], [0, 2], [1, 1], [1, 2], ], [ [0, 1], [0, 2], [1, 1], [1, 2], ], ], I: [ // ... ], L: [ // ... ], L2: [ // ... ], Z: [ // ... 2022. 2. 11.
[백준] 13460번 - 구슬 탈출 2 (파이썬) # 구슬 탈출 2 from collections import deque import sys input = sys.stdin.readline # . # 0 R B => 빈칸, 장애물, 구멍, 빨간구슬, 파란구슬 N, M = map(int, input().split()) arr = [] red_x, red_y = 0, 0 blue_x, blue_y = 0, 0 for i in range(N): arr.append(list(input().strip())) for j in range(len(arr[i])): if arr[i][j] == 'R': red_x, red_y = i, j arr[i][j] = '.' elif arr[i][j] == 'B': blue_x, blue_y = i, j arr[i][j] = '.. 2022. 2. 11.
[백준] 13459번 - 구슬 탈출 (파이썬) # 구슬 탈출 from collections import deque import sys input = sys.stdin.readline # . # 0 R B => 빈칸, 장애물, 구멍, 빨간구슬, 파란구슬 N, M = map(int, input().split()) arr = [] red_x, red_y = 0, 0 blue_x, blue_y = 0, 0 for i in range(N): arr.append(list(input().strip())) for j in range(len(arr[i])): if arr[i][j] == 'R': red_x, red_y = i, j arr[i][j] = '.' elif arr[i][j] == 'B': blue_x, blue_y = i, j arr[i][j] = '.'.. 2022. 2. 11.