The 3rd Series Problem Set

  1. Confused Automaton
  2. Towers of Zeofine
  3. The Sign of Beauty
  4. Desperate Santo
  5. Covering a Carpet

1. Confused Automaton

In 2020 the Mars-exploration was in full action. Once, a message about strange behaviour of the automaton Z-10 was recieved in the CSP (Control of Searching the Planets). On its return to base, Z-10 managed to get back to upper deck, but there some of its motor-operating circuits broke down. Now, it can move south or east, only in multiples of 100m (it can't turn and counter-cycle is blocked). Fortunatelly, the base is south-east of its position, but between the base and Z-10 there are many obstacles (whirling magnetic fields, ion clouds, gaps, abysses) that can't be overrun. And it is demanded, that Z-10 undertakes as much work, as is possible, as it was planned.

Task: Input consists of number N - the width of the map (N<=100) and matrix NxN integers, that represent the map. One cell correspond to one square 100x100m. Obstacles are negative numbers, positive numbers denote squares, where there is some work needed of Z-10 and the rest is zero. Next, there are coordinates (R,S) of Z-10. Base is situated at (N,N). Your program should find a route for Z-10, so that it doesn't contain any obstacles in it and has as many 'work-places' as possible in it. A route is sequence of squares, beginning in (R,S) and terminating in (N,N), such that every square in sequence is to south (under) or to east (on right) from previus one. If there are more than one such route, your program will output one of them, if there is no such route, your program will output appropriate message.

Example:
Input:
N=3, R=1, S=1
Map:

 0  1  1
 0 -1 -1
 0  3  0

Output:
The optimal route:
(1,1), (2,1), (3,1), (3,2), (3,3)


2. Towers of Zeofine

After many adventures, Zeofine managed to accomplish someting unthinkable - she returned to her motherland - Galapagos Islands. Before that, she's seen quite a lot of stuff in the world, and all the adders, the herons and even turtle-mates started to inquire Zeofine. They were interested especially in Europe. In Europe, Zeofine was fascinated by castles and she wanted to draw some for them, but she soon realised, that she has to teach them something about towers, first.

Towers of size D and grades 1 and 2 are on fig. 1 and fig. 2. A tower of grade s+1 we can construct from lower-grade towers in this manner: first, we draw vertical line (of length D), then we continue with tower of degree s and size D/2. Next to this tower, there is a grop of towers, that we could construct by turning s-grade tower upside down, and finally after another s-grade tower there is vertical line (of length D).

Towers for s=1,2,3

Task: Your program will for input S and D print a sequence of commands for Zeofine, so that she would draw a towerof grade S and of size D. Zeofine performs commands: FORWARD A (moves forward in current direction by length A), LEFT A and RIGHT A (changes current direction by angle A).


3. The Sign of Beauty

Once upon a time, there was a king a he had a only doughter. And she was as pretty as she was stupid. In fact, even Magic Mirror in neigbouring Snow-beauty kingdom did not know worse gargoyle than she was and even stupid Johny wouldn't have married her neither along with a half the kingdom. And everyone appreciated her wisdom and it seemed, she didn't need to be pretty. But only by the day, when her father decided to make her a queen, since the God didn't bless him with a son and a son-in-law wasn't in reach. Despite prencess's wisdom, how could she, with her appearence, represent her country? And so princess tried many plastic surgeons, many beauty salons, but the result wasn't getting better. The only hope, that remained, was an old witch, Kirka. As weird liquid bubbled in the boiler, Kirka, whispering something for herself, seated princess onto dusty armchair. And, strangely, the spell has worked. From flavoured vapour above boiler, a diagram formed and tenderly landed on Kirka's courtains. It was the Universal Sign of Beauty. Princess has to copy sign to paper before it flies away. But she can't elevate her pen before entire sign is copied. Princess manages it, of course, but try to persuade Kirka, that it doesn't have anythink to do with magic!

Task: Input describes the sign. It consists of several vertices, some of them connected by lines. First line consists of N and M, where N is the number of vertices and M is the number of lines. Every vertex is given a number 1,...,N. Following M lines contains pairs of numbers representing end vertices of a line. Your program should output a sequence of vertices, that gives the order in which lines can be drawn. Every line should be drawn exactly.

Example:
Input:
5 8
1 2
1 4
1 3
3 5
5 4
2 3
2 4
3 4

Output:
1 3 5 4 2 3 4 1 2


4. Desperate Santo

Santo turned and before him appeared a table full of food. He came to it to take some titbit and ... BZZZZZZZZZZZZZZZ. Santo's hand quickly moved to switch off the alarm clock but it was only thrown to the floor. When he finally woke up, he saw what had happened. Everywhere around him were coq-wheels from broken device. He sighed and began trying to repair it. Santo is very skillful and after some time he decided to wind it. Alarm clock was repaired, although its hands were turning counter-clockwise. Now Santo is trying to repair it again, but he is so confused because he does not know the direction of turning cog-wheels.

Task: Input for your program consists of number of cog-wheels n descriptions of all cog-wheels and direction of rotation of the first cog-wheel in a list. Desription of each cog-wheel consists of its radius and coordinates of centre. Your program should determine the speed and direction of every cog-wheel. You can assume that no two cog-wheels intersect in plane but they can touch each other. If two cog-wheels K1, K2 touch, their directions must be opposite. Further, if K1 has radius r1 and speed of turning omega1 for i=1,2, following equation holds omega1/omega2 = r2/r1. The speed of the first cog-wheel is 1 revolution per minute. If it is impossible to hold all given conditions, the alarm clock ceased (your program should write Alarm clock stopped). On the contrary some cog-wheels may stand (their speed is 0), if they have no connection to the first cog-wheel (in this case your program writes "Some cog-wheels stand.")

Coordinates and radiuses are real numbers. You should take care about round-off errors (pay attention to comparing).

Example:

Picture of two
alarm clocks

Output for the left alarm clock:

        Speed         Direction
----------------------------------------
K1      1             counter-clockwise
K2      1.828         counter-clockwise
K3      1.828         clockwise
K4      1.828         clockwise
K5      1.828         counter-clockwise

Output for the rigth alarm clock:
Alarm clock stopped.


5. Covering a Carpet

The hustle and bustle of Kiribati increases every minute. The chief of neighbouring archipelago is visiting his neighbours and he will be here in some hours. Natives would like to give him a tumultuous welcome. They have got somewhere a long red carpet and decided to place it from the airport to the main settlement. Soon they have found many holes in it and now they are trying to cover them. In many Kiribati households they have small red rugs which have the same width as the carpet but are only 1 meter long. Somebody got an idea to use them for covering the holes. They would like to use as small number of rugs as possible because many households will miss it.

Task: You are given the length of carpet d, number of holes n and the distances from airport to start and to end point of every hole (in meters). Write a program which outputs minimal number of rugs needed for covering the holes. Every hole must be covered and no rug can be cut (it will be returned to its owner after ceremony) although rugs can overlap. Further, your program should output the way of placing the rugs.

Important part of your solution is a proof that your algorithm work correctly, e.g. that it always covers all holes using the smallest possible number of rugs.

Example:
Input:
d=10, n=3
Damaged parts:

Start     End
1.2       1.3
5.4       6.5
1.95      2.1

Output:
Minimal number of rugs is 3.
Placing of rugs:

Start     End
1.15      2.15
5.4       6.4
5.5       6.5

1998, Organizers of the CSP