아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Navigating the City

시간 제한1초메모리 제한1024 MB

요약
S와 E가 표시된 도시 도로 격자 지도에서 유일한 최단 경로를 찾아 방향 문자와 이동 블록 수로 출력한다.
난이도

보통10점 중 6점

유형
BFS, 그래프, 구현, 최단 경로
정답자
아직 제출이 없습니다

문제

A dip in the milk market has forced the cows to move to the city. The only employment available is in the venerable field of taxi-driving. Help the cows learn their way around the city.

Given a city map with E (1 ≤ E ≤ 40) east/west street locations and N (1 ≤ N ≤ 30) north/south street locations, create instructions for a taxi driver to navigate from the start of his route (marked 'S') to the end (marked 'E'). Each instruction is a direction (one of 'N', 'E', 'S', or 'W') followed by a space followed by an integer that tells how many blocks to drive in that direction. If multiple routes are available, your program should output the shortest route. The shortest route is guaranteed to exist and be unique.

The map is depicted as a grid of '+'s that represent intersections and a set of roads depicted as '-' and '|'. Buildings and other obstacles are shown as '.'s. Here is a typical map:

+-+-+.+-+-+
|...|.....|
+-+.+-+-+-+
..|.......|
S-+-+-+.E-+

The taxi should go east, north, west, north, east two blocks, and so on. See the output format and sample solution below for its complete route.

입력

  • Line 1: Two space-separated integers, N and E.
  • Lines 2..2*N: These lines each contain 2*E-1 characters and encode the map of the street. Every other input line gives the data for the east/west streets; the remaining lines show the north/south streets. The format should be clear from the example.

출력

  • Lines 1..?: Each line contains a direction letter and a number of blocks to travel in that direction.

예제1

  1. 예제 1

    입력
    3 6
    +-+-+.+-+-+
    |...|.....|
    +-+.+-+-+-+
    ..|.......|
    S-+-+-+.E-+
    
    예상 출력
    E 1
    N 1
    W 1
    N 1
    E 2
    S 1
    E 3
    S 1
    W 1