-
[백준 문제풀이] 얼렁뚱땅 3190 뱀 풀이얼렁뚱땅 백준 문제풀이 2022. 10. 12. 17:23
https://www.acmicpc.net/problem/3190
3190번: 뱀
'Dummy' 라는 도스게임이 있다. 이 게임에는 뱀이 나와서 기어다니는데, 사과를 먹으면 뱀 길이가 늘어난다. 뱀이 이리저리 기어다니다가 벽 또는 자기자신의 몸과 부딪히면 게임이 끝난다. 게임
www.acmicpc.net
from collections import deque def turn_dir(current, what) : east = [0, 2, 1, 3] west = [0, 3, 1, 2] if what == 'L' : idx = west.index(current) if idx + 1 == 4 : return west[0] else : return west[idx + 1] else : idx = east.index(current) if idx + 1 == 4 : return east[0] else : return east[idx + 1] n = int(input()) apple_num = int(input()) arr = [[0]*n for _ in range(n)] for i in range(apple_num) : x, y = map(int,input().split()) arr[x-1][y-1] = 1 dir = int(input()) direction = [0] * 10001 #1초가 의미하는 숫자 0 for i in range(dir) : a, b= input().split() direction[int(a)] = b # 동 서 남 북 dx = [0, 0, 1, -1] dy = [1, -1, 0, 0] current_d = 0 q = deque([[0,0]]) arr[0][0] = -1 # -1 : 지금 뱀 꿈틀 time = 1 x , y = 0, 0 while True : nx = x + dx[current_d] ny = y + dy[current_d] # 벽에 부딪히는지 보고, 자기 몸에 부딪히는지 봐야함 if 0<=nx<n and 0<=ny<n and arr[nx][ny]!=-1: # 일단 몸 늘려 q.append([nx,ny]) #사과 있다 -> 사과 먹어 if arr[nx][ny] : arr[nx][ny] = -1 #사과 없다 -> 꼬리 땡겨 else : arr[nx][ny] = -1 re_x, re_y = q.popleft() arr[re_x][re_y] = 0 x, y = nx, ny if direction[time] != 0 : current_d = turn_dir(current_d,direction[time]) time += 1 else : break print(time)
'얼렁뚱땅 백준 문제풀이' 카테고리의 다른 글
[백준 문제풀이] 얼렁뚱땅 1027번 고층건물 풀이 (0) 2022.10.21 [백준 문제풀이] 얼렁뚱땅 16236 아기상어 풀이 (0) 2022.10.18 [백준 문제풀이] 얼렁뚱땅 14890 경사로 풀이 (0) 2022.10.12 [백준 문제풀이] 얼렁뚱땅 14499 주사위 굴리기 풀이 (0) 2022.10.11 [백준 문제풀이] 얼렁뚱땅 17114 미세먼지 안녕! 풀이 (0) 2022.10.10