728x90
반응형
SMALL
엣지가 없는 문제였습니다. ㅜㅜㅜ 진짜 진짜 진짜 간만에 원트...
https://www.codetree.ai/training-field/frequent-problems/problems/dragon-curve/description
예시대로 100 x 100 배열을 만든다음 경로 만큼 복사해 넣고 그 경로를 따라 True 처리,
마지막으로 4칸이 전부 True 인 만큼 answer += 1을 해줘서 풀었습니다.
import copy
dy, dx = [0, -1, 0, 1], [1, 0, -1, 0]
n = int(input())
info = [list(map(int, input().split())) for _ in range(n)]
answer = 0
graph = [[False for _ in range(101)] for _ in range(101)]
def trans_true(y, x, road):
global graph, dy, dx
for d in road:
y = y + dy[d]
x = x + dx[d]
graph[y][x] = True
for y, x, d, g in info:
road = [d]
for i in range(g):
copy_road = copy.deepcopy(road)
copy_road = reversed(list(map(lambda x: (x + 1) % 4, road)))
road += copy_road
graph[y][x] = True
trans_true(y, x, road)
for y in range(101):
for x in range(101):
try:
if graph[y][x] == True and graph[y][x+1] == True and graph[y+1][x] == True and graph[y+1][x+1] == True:
answer += 1
except:
continue
print(answer)
728x90
반응형
LIST