PS/This
상하좌우
RUBY_루비
2020. 8. 4. 10:39
출처::
분류:: 시뮬레이션
1. 문제 이해 및 해결과정
- 연산횟수는 이동횟수에 비례, O(n)
2. 풀이방법
1. 시뮬레이션: 일련의 명령에 따라서 개체를 차례대로 이동시킴
#상하좌우
#
import sys
sys.stdin = open("input.txt","r")
n=int(input())
plans=input().split()
dh=[-1,1,0,0]
dw=[0,0,-1,1]
dir=['U','D','L','R']
h,w=1,1
for plan in plans:
for i in range(len(dir)):
if plan==dir[i]:
nh=h+dh[i]
nw=w+dw[i]
if nh<1 or nw<1 or nh>n or nw>n:
continue
h,w=nh,nw
print(h,w)
3. 오답원인
4. 알게된 점
- 완전탐색: 모든 경우의 수를 주저 없이 다 계산하는 해결 방법
- 시뮬레이션: 문제에서 제시한 알고리즘을 한 단계씩 차례대로 직접 수행