Algorithms/Simulation

드래곤 커브 [15685] with 파이썬

Louisus 2020. 5. 27. 00:13
728x90

N = int(input())
map_list = [[
0]*101 for _ in range(101)]

dirs = {
0:(1,0), 1:(0,-1), 2: (-1,0), 3: (0,1)}

# d=시작방향 / g=세대
for _ in range(N):
    x
, y, d, g = map(int, input().split())


    curve_list = [d]

   
for _ in range(g):
        curve_list += [(i+
1)%4 for i in curve_list[::-1]]

    map_list[y][x] =
1
   
for curve in curve_list:
        x = x+dirs[curve][
0]
        y = y+dirs[curve][
1]
        map_list[y][x] =
1

cnt = 0
for i in range(100):
   
for j in range(100):
       
if map_list[i][j] and map_list[i][j+1] and map_list[i+1][j] and map_list[i+1][j+1]:
            cnt +=
1
print(cnt)

 

 

-------

 

다른사람풀이:

 

N = int(input())
map_list = [[
0]*101 for _ in range(101)]
data_list = [
list(map(int, input().split()))]
dirs = {
0:(1,0), 1:(0,-1), 2: (-1,0), 3: (0,1)}

def rotation(x,y,ex,ey):
    dx
, dy = x-ex, y-ey
    nx
, ny = ex-dy, ey+dx
   
return nx, ny

while data_list:
    x
, y, d, g = data_list.pop(0)
    map_list[y][x] =
1
   
q = [(x,y), (x+dirs[d][0], y+dirs[d][1])]
    map_list[q[
1][1]][q[1][0]] = 1

   
gen = 0
   
while gen < g:
        ex
, ey = q[-1]
        nq = []
       
for x,y in q[:-1][::-1]:
            nx
, ny = rotation(x,y,ex,ey)
            nq.append(((nx
, ny)))
           
if nx < 0 or nx >= 101 or ny < 0 or ny >= 101:
               
continue
           
map_list[ny][nx] = 1
       
q += nq
        gen +=
1
cnt = 0
for i in range(100):
   
for j in range(100):
       
if map_list[i][j] and map_list[i+1][j] and map_list[i][j+1] and map_list[i+1][j+1]:
            cnt+=
1
print(cnt)

 

# 너무 복잡....