Bilkent Annual Programming Contest

Sample Problems

The following problems are typical of the sorts of programs you may be expected to write in our contest. They are not particularly difficult, but do require a few moments thought! The actual question set will contain a range of questions such that every team should be able to solve at least one or two of them.


1) Write a program which produces a rectangular spiral which, starting from the top left corner, first heads right then down, before turning back left and then up, almost to the starting point, before turning in towards the center. The spiral must be drawn using the asterisk (*) symbol, leaving a single space between adjacent lines. Your program, to be called P1.EXE must read the height and width of the spiral from file P1.IN (which will contain the values on a single line seperated by a space.) The height and width will always be less than 100. The resulting spiral alone must be written to the P1.OUT file.

Examples:  
P1.IN   P1.OUT           P1.IN    P1.OUT
-----   ------           -----    ------
8 10    **********       8 4      ****
                 *                   *
        ******** *                ** *
        *      * *                *  *
        * *    * *                *  *
        * ****** *                *  *
        *        *                *  *
        **********                ****

2) This problem involves determining the position of a robot exploring a pre-Columbian flat world. Given the dimensions of a rectangular grid and a sequence of robot poistions and instructions, you are to write a program P2.EXE that determines for each sequence of robot positions and instructions the final position of the robot.

A robot position consists of a grid coordinate (a pair of integers: x-coordinate followed by y-coordinate) and an orientation (N,S,E,W for North, South, East and West). A robot instruction is a string of the letters 'L', 'R', and 'F' which represent, respectively, the instructions:

The direction North corresponds to the direction from grid point (x,y) to grid point (x, y+1). Since the grid is rectangular and bounded, a robot that moves "off" the edge of the grid is lost forever. However, lost robots leave a robot "scent" that prohibits future robots from dropping off the world at the same point. The scent is left at the last grid position the robot occupied before disappearing over the edge. An instruction to move "off" the world from a grid point from which a robot has been previously lost is simply ignored by the current robot.

Input will be read from file P2.IN whose first line contains the upper-right coordinates of the rectangular world. The lower-left coordinates are assumed to be 0,0. The remaining input consists of a sequence of robot positions and instructions (two lines per robot). A position consists of two integers specifying the initial coordinates of the robot and an orientation (N,S,E,W), all separated by spaces on one line. A robot instruction is a string of the letters 'L', 'R' and 'F' on one line. Each robot is processed sequentially. You may assume that all initial robot positions are within the specified grid and that the maximum value for any coordinate is 50. All instruction strings are less than 100 characters in length.

All output should be written to the P2.OUT file. For each robot position/instruction in the input, the output should indicate the final grid position and the orientation of the robot. If a robot falls off the edge of the grid the word "LOST" should be printed after the position and orientation.

Sample input:
5 3
1 1 E
RFRFRFRF
3 2 N
FRRFLLFFRRFLL
0 3 W
LLFFFLFLFL

Sample Output:
1 1 E
3 3 N LOST
2 3 S