[Python] [BOJ] 드래곤 커브(15685)

긍정왕·2021년 8월 16일
2

Algorithm

목록 보기
69/69
post-thumbnail

💡 문제 해결



🧾 문제 설명


문제보기



🖨 입출력



📝 풀이

import sys


input = sys.stdin.readline
dx, dy = [1, 0, -1, 0], [0, -1, 0, 1]

def dragon_curve(cnt, tmp_list):
    for generation in range(1, cnt + 1):
        standard = tmp_list[-1]
        for x, y in reversed(tmp_list[:-1]):
            tmp_list.append(((y - standard[1]) * -1 + standard[0], x - standard[0] + standard[1]))
    
    return tmp_list



N = int(input())
points = [list(map(int, input().split())) for _ in range(N)]

arr = [[0] * 101 for _ in range(101)]
for x, y, d, g in points:
    nx, ny = x + dx[d], y + dy[d]
    point_list = dragon_curve(g, [(x, y), (nx, ny)])

    for i, j in point_list:
        arr[i][j] = 1

answer = 0
for i in range(100):
    for j in range(100):
        if arr[i][j]:
            if arr[i + 1][j] and arr[i][j + 1] and arr[i + 1][j + 1]:
                answer += 1

print(answer)

profile
Impossible + 땀 한방울 == I'm possible

1개의 댓글

comment-user-thumbnail
2021년 12월 10일

코드 깔끔해서 좋아요 ㅎㅎ

답글 달기