문제
https://www.acmicpc.net/problem/1913
풀이
python3
import time
dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]
def solution(now_x, now_y):
direction = 0
now_num = N*N
while True:
if now_num <= 0:
break
if 0 <= now_y < N and 0 <= now_x < N and snail_list[now_y][now_x] == 0:
snail_list[now_y][now_x] = now_num
now_num -= 1
now_x += dx[direction]
now_y += dy[direction]
else:
now_x -= dx[direction]
now_y -= dy[direction]
direction = (direction + 1) % 4
now_x += dx[direction]
now_y += dy[direction]
if __name__ == '__main__':
N = int(input())
find_num = int(input())
snail_list = [[0] * N for i in range(N)]
solution(0, 0)
for i in range(N):
for j in range(N):
print(snail_list[i][j], end=' ')
if snail_list[i][j] == find_num:
find_x, find_y = j + 1, i + 1
print()
print(find_y, find_x)
아쉬웠던점
'algorithm > exercise' 카테고리의 다른 글
[BOJ 19583] 백준 19583 싸이버개강총회 (0) | 2021.08.31 |
---|---|
[BOJ 1963] 백준 1963 소수경로 (0) | 2021.08.30 |
[BOJ 2263] 백준 2263 트리의 순회 (0) | 2021.08.29 |
[BOJ 2638] 백준 2638 치즈 (0) | 2021.08.28 |
[BOJ 6593] 백준 6593 상범 빌딩 (0) | 2021.08.28 |