5th Round: 12th of February 1997

1st Problem
2nd Problem
1st Problem: Another kind of Hanoi (45 points)


Having 2 <= n <= 10 rods on which there are coloured balls. The colours are counted from 1 to n. Arrange the balls on the rods, so that on each of them to be n balls counted, from the bottom to the top, from 1 to n. For moving the balls use an auxiliry rod, marked n+1. On every rod the maximum number of balls is n. A ball can be moved on another rod, if on this rod there is enough room and if on the top of the ball there isn't another one.
The final position must look like this :

        n       n      n       ...      n          |
       n-1     n-1    n-1              n-1         |
        .       .      .                .          .
        .       .      .                .          .
        .       .      .                .          .    <-- rods
        3       3      3                3          |
        2       2      2                2          |
        1       1      1                1          |
     ----------------------------------------------------
        1       2      3                n         n+1   <--the number
                                                           of the rod
The initial configuration is read from the file "dates" having the following structure: on the first line there is the number of the rods n on the following n lines there are n numbers from 1 to n, separated by spaces, representing the placement of the balls on every rod, placement read from the bottom to the top.
The output file "rez" contains on every line excepting the last one a number m, having the format: i x y where: i represents the colour; x and y the number of the rod from which, respectively on which, the ball is moved; these numbers are between 1 and n+1. m represents the total number of moves
Example :
file dates:
2                                         1     2     |
1 1                                       1     2     |
2 2                                     -----------------
                                          1     2     3
file rez:
2 2 3
2 2 3                                     2     2     |
1 1 2                                     1     1     |
2 3 1                                   -----------------
2 3 2                                     1     2     3
5   

Time for test : 1min/test on a 586 at 133MHz.
prof.Maria and Adrian Nita
"Emanuil Gojdu" Highschool
Oradea

2nd Problem: Numbers (30 points) (it's easier than it seems !)

Find out all the positive integer numbers n < 60.000 with the following feature: if 1 < m < n and if mis a positive integer and prime number with n, then m is a prime number.
Write in the file 'numsol' having the structure:
n1
n2
...
nk


where ni are the requested numbers.
Time for test : 10".
prof. Maria and Adrian Nita
"Emanuil Gojdu" Highschool
Oradea

[Index] [Important Informations] [Participants] [4th Round] [6th Round]