Programming contests

DEIK Regionális Programozó Csapatverseny, középiskolai kategória, 2016. december 4.

December 4, 2016 10:10 AM – December 4, 2016 3:10 PM

RoboBot

Program a robot to search for a target, 'E', on a maze of size 6 × 6. The robot starts at the cell marked with the character 'S'. Exploring the grid, it can only move in 4 directions: North, East, South, or West (never diagonally). There are three walls of size between 1 and 6 on this maze.

You have to find one of the shortest paths from the start marker to the end marker. Only moves between adjacent grid squares are allowed; adjacent means that the grid squares share an edge and are not separated by a wall. It is not allowed to leave the grid.

Input Specification

The input consists of several test cases. Each test case consists of five lines. The first line contains the column and row number of the square with the start marker. The second line contains the column and row number of the square with the end marker. The third, fourth, and fifth lines specify the locations of the three walls. The location of a wall is specified by either the position of its left end point followed by the position of its right end point (in case of a horizontal wall) or the position of its upper end point followed by the position of its lower end point (in case of a vertical wall). The position of a wall end point is given as the distance from the left side of the grid followed by the distance from the upper side of the grid.

You may assume that the three walls don't intersect with each other, although they may touch at a corner of a cell, and that the wall end points are on the grid. Moreover, there will always be a valid path from the start marker to the end marker. Note that the sample input specifies the maze in the picture above.

The last test case is followed by a line containing two zeros.

Output Specification

For each test case, print the description of the shortest path from the start marker to the end marker in one line. The description should specify the direction of every move ('N' for up, 'E' for right, 'S' for down, and 'W' for left).

There can be more than one shortest path, in this case you can print any of them.

Sample Input

  1. 1 6
  2. 2 6
  3. 0 0 1 0
  4. 1 5 1 6
  5. 1 5 3 5
  6. 0 0
download as text file

Output for Sample Input

  1. NEEESWW
download as text file
University of Debrecen; Faculty of Informatics; v. 03/01/2019