Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- singing voice synthesis
- DCTTS
- 한국어 음성 합성
- 딥러닝 음성 합성
- Vocoder
- deep voice
- 딥러닝 보코더
- 윈도우
- melgan
- 한국어 tts
- 학습
- tacotron
- YOLO
- 트레이닝
- 노래합성
- korean tts
- 음성 합성
- 딥러닝
- 타코트론
- 보코더
- you only look once
- waveglow
- TTS
- text-to-speech
Archives
- Today
- Total
chldkato
백준 1726 로봇 (파이썬) 본문
https://www.acmicpc.net/problem/1726
1726번: 로봇
많은 공장에서 로봇이 이용되고 있다. 우리 월드 공장의 로봇은 바라보는 방향으로 궤도를 따라 움직이며, 움직이는 방향은 동, 서, 남, 북 가운데 하나이다. 로봇의 이동을 제어하는 명령어는 다음과 같이 두 가지이다. 명령 1. Go k - k는 1, 2 또는 3일 수 있다. 현재 향하고 있는 방향으로 k칸 만큼 움직인다. 명령 2. Turn dir - dir은 left 또는 right 이며, 각각 왼쪽 또는 오른쪽으로 90° 회전한다. 공장 내 궤
www.acmicpc.net
1. 동서남북을 dx, dy로 각각 0부터 3까지 인덱스를 매칭
2. 현재지점에서 오른쪽, 왼쪽 회전을 수행
3. 현재방향의 앞칸이 이동할 수 있으면 1칸부터 3칸까지 이동할 수 있는 만큼 이동하면서 큐에 입력
4. 이동할 수 없으면 오른쪽, 왼쪽 회전을 수행
5. 앞의 과정을 반복하면서 목표지점과 방향에 도착하면 횟수 출력
from collections import deque
import sys
input = sys.stdin.readline
dx = [0, 0, 1, -1]
dy = [1, -1, 0, 0]
def bfs(x, y, dir):
q.append([x, y, dir])
c[x][y][dir] = 1
while q:
x, y, dir = q.popleft()
if x == x1-1 and y == y1-1 and dir == dir1-1:
print(c[x][y][dir]-1)
return
turn_r(x, y, dir)
turn_l(x, y, dir)
nx = x + dx[dir]
ny = y + dy[dir]
if 0 <= nx < m and 0 <= ny < n:
if a[nx][ny] == 0:
move(x, y, dir)
else:
turn_l(x, y, dir)
turn_r(x, y, dir)
def move(x, y, dir):
cnt = 1
nx = x; ny = y
while cnt <= 3:
nx += dx[dir]
ny += dy[dir]
if nx < 0 or ny < 0 or nx >= m or ny >= n or a[nx][ny] == 1:
return
if c[nx][ny][dir] == 0:
c[nx][ny][dir] = c[x][y][dir] + 1
q.append([nx, ny, dir])
cnt += 1
def turn_r(x, y, dir):
if dir == 0: ndir = 2
elif dir == 1: ndir = 3
elif dir == 2: ndir = 1
else: ndir = 0
if c[x][y][ndir] == 0:
c[x][y][ndir] = c[x][y][dir] + 1
q.append([x, y, ndir])
def turn_l(x, y, dir):
if dir == 0: ndir = 3
elif dir == 1: ndir = 2
elif dir == 2: ndir = 0
else: ndir = 1
if c[x][y][ndir] == 0:
c[x][y][ndir] = c[x][y][dir] + 1
q.append([x, y, ndir])
m, n = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(m)]
x0, y0, dir0 = map(int, input().split())
x1, y1, dir1 = map(int, input().split())
c = [[[0]*4 for _ in range(n)] for _ in range(m)]
q = deque()
bfs(x0-1, y0-1, dir0-1)
'백준' 카테고리의 다른 글
백준 1152 단어의 개수 (파이썬) (0) | 2020.02.18 |
---|---|
백준 1987 알파벳 (파이썬) (0) | 2020.02.18 |
백준 3184 양 (파이썬) (0) | 2020.02.18 |
백준 9205 맥주 마시면서 걸어가기 (파이썬) (0) | 2020.02.18 |
백준 10159 저울 (파이썬) (0) | 2020.02.18 |
Comments