[백준] 15685번 드래곤커브 (python, 시뮬레이션)

728x90
반응형

www.acmicpc.net/problem/15685

 

15685번: 드래곤 커브

첫째 줄에 드래곤 커브의 개수 N(1 ≤ N ≤ 20)이 주어진다. 둘째 줄부터 N개의 줄에는 드래곤 커브의 정보가 주어진다. 드래곤 커브의 정보는 네 정수 x, y, d, g로 이루어져 있다. x와 y는 드래곤 커�

www.acmicpc.net

from collections import deque
from collections import defaultdict

dict=defaultdict(int)
n=int(input())
dy,dx=[0,-1,0,1],[1,0,-1,0] # 북서남동 0 1 2 3 => 서남동북 1 2 3 0
def dragon(x,y,d,g):
    direct=[d]
    dict[(x, y)] = 1 # 시작점 저장
    x+=dx[d] # 현재 방향에서 이동 (0세대)
    y+=dy[d]
    dict[(x, y)] = 1 # 0세대 이동 저장
    for _ in range(g):
        temp=[]
        for i in range(len(direct)-1,-1,-1):
            next=(direct[i]+1)%4
            x+=dx[next]
            y+=dy[next]
            dict[(x,y)]=1
            temp.append(next)
        direct.extend(temp)




for _ in range(n):
    x,y,d,g=map(int,input().split())
    dragon(x,y,d,g)

answer=0
for x,y in list(dict.keys()):
    if dict[x+1,y] and dict[x,y+1] and dict[x+1,y+1]:
        answer+=1
print(answer)

 

풀이 참고 

hose0728.tistory.com/27

 

728x90
반응형
TAGS.

Comments