You are on page 1of 10

Bender is a depressed robot who heals his depression by partying and drinking alcohol.

To save him from a life of debauchery, his creators have reprogrammed the control system with a more rudimentary intelligence. Unfortunately, he has lost his sense of humor and his former friends have now rejected him. Bender is now all alone and is wandering through the streets of Futurama with the intention of ending it all in a suicide booth. To intercept him and save him from almost certain death, the authorities have given you a mission: write a program that will make it possible to foresee the path that Bender follows. To do so, you are given the logic for the new intelligence with which Bender has been programmed as well as a map of the city. The rules of the new Bender system:

1. 2. 3. 4.

Bender starts from the place indicated by the @ symbol on the map and heads !"UT#. Bender finishes his journey and dies when he reaches the suicide booth marked $. "bstacles that Bender may encounter are represented by # or X. $hen Bender encounters an obstacle, he changes direction using the following priorities:

!"UT#, %&!T, '"(T# and $%!T. !o he first tries to go !"UT#, if he cannot, then he will go %&!T, if he still cannot, then he will go '"(T#, and finally if he still cannot, then he will go $%!T.

5.

&long the way, Bender may come across path modifiers that will instantaneously make him

change direction. The S modifier will make him turn !"UT# from then on, E, to the %&!T, N to the '"(T# and W to the $%!T.

6.

The circuit inverters )I on map* produce a magnetic field which will reverse the direction priorities

that Bender should choose when encountering an obstacle. +riorities will become $%!T, '"(T#, %&!T, !"UT#. ,f Bender returns to an inverter I, then priorities are reset to their original state)!"UT#, %&!T, '"(T#, $%!T*.

7.

Bender can also find a few beers along his path )B on the map* that will give him strength and put

him in -Breaker. mode. Breaker mode allows Bender to destroy and automatically pass through the obstacles represented by the character X )only the obstacles X*. $hen an obstacle is destroyed, it remains so permanently and Bender maintains his course of direction. ,f Bender is in Breaker mode and passes over a beer again, then he immediately goes out of Breaker mode. The beers remain in place after Bender has passed.

8.

/ teleporters T may be present in the city. ,f Bender passes over a teleporter, then he is

automatically teleported to the position of the other teleporter and he retains his direction and Breaker mode properties.

9.

Finally, the space characters are blank areas on the map )no special behavior other than those

specified above*.

0our program should display the se1uence of moves taken by Bender according to the map provided as input. The map is divided into lines )2* and columns )3*. The contours of the map are always unbreakable #obstacles. The map always has a starting point @ and a suicide booth $. ,f Bender cannot reach the suicide booth because he is indefinitely looping, then your program should only display LOOP. For e4ample, for the map below:

###### #@E $# # N # #X # ######


Bender will follow this se1uence of moves:


INPUT:

!"UT# )initial direction* %&!T )because of the obstacle X* '"(T# )change of direction caused by N* %&!T )change of direction caused by E* %&!T )current direction, until end point $*

Line 1: the number of lines L and columns C on the map, separated by a space. The follo ing L lines: a line of the length 3 representing a line on the map. & line can contain the characters#, X, @, $, S, E, N, W, B, I, T and space character. OUTPUT:

,f Bender can reach $, then display the se1uence of moves he has taken. "ne move per line: !OUT" for

the !outh, #$!T for the %ast, NO%T" for the 'orth and &#!T for the west.

,f Bender cannot reach $, then only display LOOP.

CON!T%$INT!: 4 5 C 5 100 4 5 L 5 100 #'$(PL# : Input 10 10 ########## # # # S W # # # # $ # # # #@ # # # #E N # ########## Output SOUTH SOUTH EAST EAST EAST EAST EAST EAST NORTH NORTH NORTH NORTH NORTH NORTH WEST WEST WEST WEST SOUTH SOUTH

$)aila*le %$( : +1,(B Timeout: , seconds

The program has to read inputs from standard input The program has to write the solution to standard output The program must run in the test environment

-o nload the files pro)ided in the test script: !imple moves: in1.txt out1.txt "bstacles: in2.txt out2.txt +riorities: in3.txt out3.txt !traight line: in4.txt out4.txt +ath modifier: in5.txt out5.txt Breaker mode: in6.txt out6.txt ,nverter: in7.txt out7.txt Teleport: in8.txt out8.txt Broken wall6: in9.txt out9.txt &ll together: in10.txt out10.txt 2""+: in11.txt out11.txt 7ultiple loops6: in12.txt out12.txt

0ou have managed to find Bender. #is circuits are programmed with an algorithm which has made him lose all sense of humor or fun. 0ou decide to return his system to his original behavior. The first trait of character that you are going to work on is his passion for money. Bender can detect bank notes

several miles away. 0ou will write a program that will lead him to always find the most money possible, wherever it is. To check that your algorithm works properly, Bender is placed in a room at the entrance of a building. There is a sum of money in each of the rooms that make up this building. %ach room has e4actly two doors which you can use to get out. %ach door leads either to a new room or to the outside of the building. Bender must collect as much money as possible, by going from room to room, ithout *eing a*le to go *ack, until

he gets out of the building. Thanks to his sensors, Bender can analy8e the building right from the outset in order to detect the list of rooms and the money contained in each of them. This analysis of the rooms will be provided as input for your program so that you can implement an algorithm that will make the best decisions. %ach room in the building has a uni1ue number. %ach door of a room is marked with a number, which represents the number of the room that it opens, or E if it opens to the outside of the building. !everal doors can lead to one room but due to the layout of the building it is impossi*le for Bender to go through the same room t ice. The first room in which Bender finds himself has the number 0.

,n the e4ample above, Bender pockets 9:; by going through the rooms ;, /, < and = before leaving the building. INPUT: Line 1: the number N of rooms in the building. N follo ing lines: one line with a room number )integer*, a sum of money )integer*, the two numbers of the rooms which are accessible )integers or E if the door is an e4it*. These four values are separated by a white space. OUTPUT: &n integer representing the ma4imum amount of money that Bender can collect by taking a series of doors to reach the outside of the building. CON!T%$INT!: 0 < N < 10000

#'$(PL#: Input 15 0 17 1 2 1 15 3 4 2 15 4 5 3 20 6 7 4 12 7 8 5 11 8 9 6 18 10 11 7 19 11 12 8 12 12 13 9 11 13 14 10 13 E E 11 14 E E 12 17 E E 13 19 E E 14 15 E E Output 88

$)aila*le %$( : +1,(B Timeout: , seconds

The program has to read inputs from standard input The program has to write the solution to standard output The program must run in the test environment

-o nload the files pro)ided in the test script: "ne room: in1.txt out1.txt < rooms: in2.txt out2.txt >= rooms, small range: in3.txt out3.txt == rooms: in4.txt out4.txt >/?= rooms: in5.txt out5.txt =;=; rooms: in6.txt out6.txt @?; rooms: in7.txt out7.txt !1uare building: in8.txt out8.txt 7ultiple entries: in9.txt out9.txt

Bender is happy because hundreds of 3odinAamers have reBprogrammed his natural behavior. The problem is that these programs arenCt all e1ual. %vidently, most are too fast for Bender to fully revel in his inactivity...

Using performance measures carried out on the e4ecution time of the programs for Bender, your mission is to determine the most likely computational comple4ity from a family of fi4ed and known algorithmic comple4ities. #ere is an e4ample of performance measures recorded when running a program with different volumes of data:

,n this e4ample, the program was run with data volumes ranging from ; to =;;; items and we see that the e4ecution time, measured in microseconds, varies significantly depending on the number of items that the program processed. #ere, the curve suggests that the most likely algorithmic comple4ity is O(lo !n". INPUT: Line 1: The number N of performance measures carried out on the same program. N follo ing lines: "ne performance measure per line. %ach line contains two values: an integer nrepresenting the number of items that the program has processed and an integer t representing the e4ecution time measured to process these items in microseconds. These values are separated by a space. Dalues of n are uni1ue and sorted in ascending order. OUTPUT: The most probable computational comple4ity from amongst the following possibilities: O(1", O(lo !

n",O(n", O(n!lo !n", O(n#2", O(n#2!lo !n", O(n#3", O(2#n"


CON!T%$INT!: 5 < N < 1000 5 < n < 15000 0 < t < 10000000 #'$(PL#: Input 10 5 341 1005 26324 2005 52585

3005 78877 4005 104925 4805 125920 6105 159156 7205 188017 8105 211417 9905 258991 Output O(n

$)aila*le %$( : +1,(B Timeout: , seconds

The program has to read inputs from standard input The program has to write the solution to standard output The program must run in the test environment

-o nload the files pro)ided in the test script: ")>*: in1.txt out1.txt ")log n*: in2.txt out2.txt ")n*: in3.txt out3.txt ")n log n*: in4.txt out4.txt ")nE/*: in5.txt out5.txt ")nE/ log n*: in6.txt out6.txt ")nE<*: in7.txt out7.txt ")/En*: in8.txt out8.txt

You might also like