Algorithm(53)
-
우물 안 개구리
g = collections.defaultdict(dict) for u, v in relations: g[u][v] = 1 g[v][u] = 1 visited = set() cnt = 0 for node in range(1, N + 1): val = weights[node - 1] if len(g[node].items()) == 0: cnt += 1 continue for v, w in g[node].items(): if val
2021.09.29 -
알고리즘: 지도 자동 구축
N = 2 size = 2**N grid = [[0]*size for _ in range(size)] rows = len(grid) cols = len(grid[0]) score = 0 for y in range(rows): for x in range(cols): if ((y == 0 and x == 0) or (y == rows - 1 and x == cols - 1) or (y == rows - 1 and x == 0) or (y == 0 and x == cols - 1)): score += 2.25 elif (y == 0 or x == 0 or x == cols - 1 or y == rows - 1): score += 1.5 else: score += 1 print(int(score))
2021.09.28 -
GBC
뭐가 문제인건지.. 기본 TC는 통과.....흠.. N log (N) 알고리즘으로 구현하지 말고 그냥 NM으로 구현할까? 귀찮... import sys import bisect limits = [] test = [] N, M = map(int, sys.stdin.readline().split()) for i in range(N): limits += tuple(map(int, sys.stdin.readline().split())), for i in range(M): test += tuple(map(int, sys.stdin.readline().split())), tbl = [(0, 0)] start = 1 for length, speed in limits: tbl += (start + length - 1,..
2021.09.28 -
장애물 인식 프로그램
grid = [] N = int(sys.stdin.readline()) for _ in range(N): line = str(sys.stdin.readline()).strip() line = list(line) line = list(map(int, line)) grid += line, def dfs(y, x): if 0 == grid[y][x]: return 0 cnt = 1 grid[y][x] = 0 for oy, ox in [(1, 0), (-1, 0), (0, 1), (0, -1)]: ny, nx = oy + y, ox + x if not (0
2021.09.28 -
택배 마스터 광우
brute force algorithm ... N, M, K = map(int, sys.stdin.readline().split()) lines = list(map(int, sys.stdin.readline().split())) def get_sum(lines, K): cur = 0 idx = 0 tot = 0 while K: inc = 0 while cur + lines[idx]
2021.09.28 -
차세대 지능형 교통시스템
import sys n, T = map(int, sys.stdin.readline().split()) signals = [] for i in range(n*n): signals += list(map(int, sys.stdin.readline().split())), inters = [[[0]*4 for x in range(n)] for y in range(n)] rows = len(signals) cols = len(signals[0]) for iidx in range(n*n): y = iidx//n x = iidx%n for t in range(4): inters[y][x][t] = signals[iidx][t] signal_ways = { 1: [(0, 1), [(-1, 0), (0, 1), (1, 0..
2021.09.28