UNDERGROUND CITY PROBLEMYou are imnprisoned in one of the underground cities in of Cappadocia. Wandering around in the dark to find a way out you find by chance the map of the city. Unfortunately, there is no mark on the map pointing where you are. It is your task to find that out by exploring the city. The map of the city is a rectangular grid of unit squares. Each square is either an open square, marked with the letter O, or a part of a wall, marked with the letter W. The north direction is also shown on the map. Luckily, you have a compass at hand so you can orient the map correctly. Initially, you are on an open square. Everything starts by calling the procedure (or function) start with no arguments. You can explore the city by using the procedures (or functions) look and move. You can posinge questions in the form of a procedure (or function) call look(dir) where dir denotes the direction you are looking inat, which can be one of the characters N, S, E and W denoting north, south, east and west, respectively. Now assume the argument dir is N. The reply will be the character letter O if the square to your north is an open square, and W if it is a wall. Similarly, it is possible to look at and get information in about the other directions.neighboring squares. You can step into one of the four neighboring squares by calling move(dir) where dir denotes the direction of your step as described above. You can only move to an open square. Attempting to move into a wall would be a grave mistake. It is possible to reach any open square of the city starting from any open square. You are required to find the position of the open square where you found the map by looking (calling look(dir)) minimum number of times. Once you found the position you must report it by calling finish(x,y) where x is the horizontal (west-east) coordinate and y is the vertical (south-north) coordinate of the position. ASSUMPTIONS INPUT The input is a text file named under.inp.
OUTPUT No output file will be generated. The result found by your program must be reported by calling finish(x,y). EXAMPLE Have the following in your source file: uses undertpu.tpu; This tpu will provide the following: procedure start; { must be called first } function look (dir:char):char; procedure move (dir:char); procedure finish (x,y:integer); { must be called last }
INSTRUCTIONS FOR C/C++ PROGRAMMERS Have the following in your source file: #include "under.h" Include under.obj in project. Have the following in your source file:This will provide the following declarations: void start (void); /* must be called first */ char look (char); void move (char); void finish (int,int); /* must be called last */
Also o create a project called under which should include your program (under.c or under.cpp) and the library for interaction named underobj.obj. To do this you need to use the project menu of IDE and choose the open option to create a project, and then use add item to include your source file (under.c or under.cpp) and the file underobj.obj. Use the LARGE memory model compiler option. (Careful: This overrides the memory model mentioned in the Rules of Contest.) EVALUATION Your program will be allowed to run 5 seconds. To get full credit the number of calls to look must be the same or less than the number determined by the evaluation program. You can obtain partial credit according to the following formula: To get full credit, A, for a test case the number of calls to look, x, must be the same or less than or equal to the number, M, set by the evaluation program. Note that M is chosen as larger than (>) the minimum. In particular, M is independent of the clockwise or counter-clockwise ordering of the directions for looking. You can obtain partial credit if the number of calls to look is greater than (>) M but less than (<) twice M. The points you get for a test case is given calculated by rounding to the nearest integer the value obtained by the following formula: A if x <= M A/M (2M x) /M if M < x < 2M 0 if x ³ 2M Illegal behavior by your program will result in zero points. Illegal behaviors specific to this task are are the following:
HOW TO TRY OUT YOUR PROGRAM Create a text file called place.txt including the position of the map. Run your program. See the result in the file result.txt. The file place.txt should have one line having the horizontal and vertical coordinates of the position of the map. You need to create your own input data file under.inp. The result.txt file will contain two lines. The first line will have the arguments x and y for your call to finish (x,y). The second line will have a message of the form "You used look nnn times". Note that this trial is for checking the compatibility of your program with the library. It has nothing to do with the correctness of your solution. GRADING Your program will be allowed to run 5 seconds. |