시뮬레이션
[큐, 시뮬레이션] BOJ 3190 뱀
https://www.acmicpc.net/problem/3190 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 import sys from collections import deque input = sys.stdin.readline N = int(input()) K = int(input()) board = [[0] * N for _ in range(N)] apples = [list(map(int, input().split())) for _ in range(K)] DELTAS = deque([(0, 1..
[BFS, 시뮬레이션] 14500 테트로미노
https://www.acmicpc.net/problem/14500 14500번: 테트로미노 폴리오미노란 크기가 1×1인 정사각형을 여러 개 이어서 붙인 도형이며, 다음과 같은 조건을 만족해야 한다. 정사각형은 서로 겹치면 안 된다. 도형은 모두 연결되어 있어야 한다. 정사각형의 변 www.acmicpc.net 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 import sys input = sys.stdin.readline N, M = map(int, input().split()) board..
[시뮬레이션] BOJ 20057 마법사 상어와 토네이도
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677import sysfrom typing import List, Tuplefrom collections import dequeinput = sys.stdin.readline N = int(input())board = [list(map(int, input().split())) for _ in range(N)] deltas = deque([(0, -1), (1, 0), (0, 1), (-1, 0)]) def update_board(board:List[Li..
[시뮬레이션, BFS] BOJ 16236 아기상어
https://www.acmicpc.net/problem/16236 시뮬레이션 + dfs + dp(visited) 살짝 가미된 형태로 구현하였다. 여기서 주의할 점은 잡아먹는 물고기의 크기는 1 ~ 6이라면 커지는 상어의 크기는 무한하다는 것. size로 제한하면 초반엔 괜찮지만 상어의 크기가 9이상이 되면 무한 반복이 일어나 시간초과가 발생할 수 있다. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 ..
[시뮬레이션] BOJ 16234 인구이동
graph를 구성하고 graph 탐색하는 방식으로 구현. 이때 주의할 점은 graph를 만들때 왼, 오, 위, 아래 모두 확인해서 넣어야한다는 점. 그다음에 visited로 제외해야하는 방식이 예외케이스를 만들지 않는다. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 import sys from typing..
[시뮬레이션] 20055 컨베이어 벨트 위의 로봇
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 import sys from typing import List from collections import deque input = sys.stdin.readline N, K = map(int, input().split()) A = list(map(int, input().split())) def operate_belt(arr: List[int], N: int, K: int) -> int: limit_cnt = 0 queue = deque(arr) robot_queue = deque([0] * N) step = 0 w..
[시뮬레이션] BOJ 17144 미세먼지 안녕!
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980import sysimport copyinput = sys.stdin.readline DELTAS = ((1, 0), (-1, 0), (0, 1), (0, -1))R, C, T = map(int, input().split())arr = [list(map(int, input().split())) for _ in range(R)] # 시뮬레이션 문제 def diffuse(arr): new_arr = copy.deepcopy(arr) for y..
![[시뮬레이션] BOJ 14503 로봇 청소기](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdna%2FnmLpB%2FbtsjPrFBVUd%2FAAAAAAAAAAAAAAAAAAAAAGRsJyN62lYz8zoYTJBNWxsmjhLfLl3E6rfrnxgq-Vzs%2Fimg.png%3Fcredential%3DyqXZFxpELC7KVnFOS48ylbz2pIh7yKj8%26expires%3D1761922799%26allow_ip%3D%26allow_referer%3D%26signature%3DiC6REUorECWxbUdPywG5EZcDaGk%253D)
[시뮬레이션] BOJ 14503 로봇 청소기
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 import sys input = sys.stdin.readline N, M = map(int, input().split()) r, c, d = map(int, input().split()) arr = [list(map(int, input().split())) for _ in range(N)] DELTAS = [(-1, 0), (0, 1), (1, 0), (0, -1)] def run(board, y, x, d): result = 0 while True: if board[y][x] == 0: board[y][x] = 2 re..