본문 바로가기

Simulation22

[python] 2290. LCD Test 문제 출처 2290. LCD Test 풀이 s, n = input().split() s = int(s) col, row = 2*s+3, s+2 def one(s): global text for i in range(col): if i in (0, s+1, col-1): text[i] += ' '*row else: text[i] += ' ' * (row-1) + '|' return text def two(s): global text for i in range(col): if i in (0, s+1, col-1): text[i] += ' ' + '-'*s + ' ' else: if i < s+1: text[i] += ' ' * (row-1) + '|' else: text[i] += '|' + ' ' * (ro.. 2019. 10. 29.
[python] 17471. 게리맨더링 문제 출처 17471. 게리맨더링 풀이 from itertools import combinations N = int(input()) population = list(map(int, input().split())) connection = {i: [j-1 for j in list(map(int, input().split()))[1:]] for i in range(N)} def is_connected(comb): check = [1 if i in comb else 0 for i in range(N)] visited = [0]*N visited[list(comb)[0]] = 1 q = connection[list(comb)[0]] while q: nxt = [] for i in q: if check[i] and.. 2019. 10. 19.
[python] 17143. 낚시왕 문제 출처 17143. 낚시왕 풀이 from collections import deque R, C, M = map(int, input().split()) sharks = [list(map(int, input().split())) for _ in range(M)] # y, x, 속력, 방향, 크기 dr, dc = (0, -1, 1, 0, 0), (0, 0, 0, 1, -1) def move(shark): r, c, s, d, z = shark while s > 0: nr, nc = r + dr[d], c + dc[d] s -= 1 if nr > R: d = 1 nr -= 2 elif nr C: d = 4 nc -= 2 elif nc < 1: d = 3 n.. 2019. 10. 19.
[python] 5648. 원자 소멸 시뮬레이션 문제 출처 5648. 원자 소멸 시뮬레이션 풀이 tc = int(input()) for _ in range(tc): n = int(input()) atoms = [] mt, mr, mb, ml = 0, 0, 0, 0 for i in range(n): x, y, d, e = map(int, input().split()) if x > mr: mr = x if x mt: mt = y if y < mb: mb = y atoms.append([x*2, y*2, d, e]) mt *= 2 mr *= 2 mb *= 2 ml *= 2 direction = {0: (0, 1), 1: (0, -1), 2: (-1, 0), 3: (1, 0)} answer = 0 while atoms: c.. 2019. 9. 6.