The 3rd Series Problem Set

  1. The Garden of Mr. Zavis
  2. About the Tiribaki Princess
  3. Lord Zoltan Is Betting
  4. DAHGLJBVJ VYSC
  5. The Mystery of Mekka


1. The Garden of Mr. Zavis

Mr. Zavis bought a new garden. But it did not turn to yield a profit. Therefore he decided to take part in the Original Garden Contest. He hopes to win the contest and be awarded with a lot of money. Only square gardens can take part in this contest. The garden wins the contest if no other known square garden is similar to it. Mr. Zavis got hold of a list of all the known square gardens and started to compare.

Task: The input data consist of number N (size of the garden) and two matrixes of type NxN containing numbers 0 and 1 (0 denotes empty place, 1 denotes flowerbed). Write a program which determines whether these two gardens are similar. Two gardens are similar if one can be obtainted from the other using several operations of rotation by 90 degrees and symmetry about the x or y axis.

Example:
Input:
N = 4
1 0 0 0 0 0 1 0
0 0 1 1 1 0 1 0
0 1 0 0 0 1 0 0
0 0 1 0 0 0 0 1

Output:
Gardens are similar (the second can be obtained from the first one by turning by 90 degrees right and using symmetry about the x-axis.


2. About the Tiribaki Princess

The princess of Tiribaki refused to marry the Burundi chieftain. It looked like another international conflict. But both sides were able to come to an agreement. They will play one match of their national game and the winner will decide. The rules of this game are simple. They will cut two necklaces belonging to a princess and they will arrange beads of each necklace to a separate pile. After this they will move alternatingly. Each player removes during one move several beads from one of the piles. The number of beads removed during one move should be at least 1 and cannot exceed given constant k. The game is over when all the beads are removed. There are free alternatives of the game. In the alternative A loses the player who removed odd number of beads during entire game. In the alternative B loses the player who removes the last bead. In the alternative C wins the player who removes the last bead. The alternative used in a match as well as the number k will be chosen by lot before the match.

Task: Write a program which for given game determines for which player the winning strategy exists. It means to decide which player can win regardless of the moves of his rival. Your program should be also able to advice to the winning player how to move if the player enters the moves of his rival. The input of your program consists of numbers N1 and N2 giving the numbers of beads in both piles, the number k and alternative H. The princess moves first.

Note: In the alternative A you can assume that the sum N1 + N2 is an odd number.


3. Lord Zoltan Is Betting

Lord Zoltan loves horse races. He also loves betting. Each Sunday he meets his friends at the horse races. Once they started to talk about their bets. "I betted two hundred gold coins that the Yellow Star will be better than Slyboot," said one of them . "And I betted barrel of my best wine that Artefax will be better than Halifax," said another lord. Lord Zoltan betted twenty-five silver coins that his favoured horse Iron will be better than Wooden Leg.

They discoverd that each of them did a bet of the type "the horse 1 will be better than the horse 2". After the races some of the friends went home happy, others (including Zoltan) tried not to show their sorrow. Going home Zoltan started to think. He wanted to know whether it was possible for all of them to win. Task: The input consist of the number of horses M, the number of bets N and N bets - bet "the horse A(i) will be better than the horse B(i)" will be given as the pair of numbers A(i), B(i). Write a program which finds one possible result of races (i.e. the order in which the horses finished) such that all the lords will win their bets. If no such result exists write appropriate message.

Example:
Input:
M=7, N=4
Bets:
1 2
2 3
3 4
3 1
Output:
No such result exist.


4. DAHGLJBVJ VYSC

YZDJGLC GR JQY CGAY JDAYC VYSC LYKYDNYZ JYMYILBA KGVJBDVDVI NYLE DAHGLJBVJ VYSC. JQDC AYCCBIY SBC YVKGZYZ JG WYYH DJ CYKLYJ. YZDJGLC JLDYZ RGL QGULC JG ZYKGZY JQY AYCCBIY OUJ DV NBDV. QYMH JQYA BVZ ZYKGZY JYPJ GR JQY AYCCBIY (SDJQ B QYMH GR EGUL HLGILBA). CYVZ UC VGJ GVME ZYKGZYZ JYPJ GR JQY AYCCBIY OUJ BMCG JQY AYJQGZ OE SQDKQ EGU GOJBDVYZ DJ DVKMUZDVI JQY HLGILBA EGU SLGJY RGL JQDC HULHGCY BVZ ZYCKLDHJDGV GR JQDC HLGILBA.

TBYVINQGSVGCO XSJMEEDJF
LCSIIUU BJ MPUPTBOMU JF IZQRGVFQ XQ CR VKDU EIBVR EPAHKUVSPT SST HESYJAK
MPUPTBOMU BEI UVETTJFMPHYC IPBH KO NVIFAXKON EPE OVCAVPKB NJVFE XJF EIEFAX
EMVQCUVG EINRIFF WCJQ XJF FTQLRWOBA JQS GLG SRKKPA SH TBYVI NQGSVGC UUMU
DYMOBGME DUEPHRW CSR GCVFIF CL XJF EEKOSSTFFX EVYXKWNXKPA XJF UETWRWV PS
OQIYVCCVW KT UMIIRV KO BXJFE GQVAXTJRW QG FSWUU EOFEMEB NW YFYP VIR LCSIIUU
VW GWRR HJSXA QRV EFAX JJTLGS VR UPZI CSREU UUMU GNGVT JMNM CVQCNFNZ UEXF
TSQE RJHFPX QO GLG FPSPPZC QG GLGTR GQVGVKFF XJFL HQ OBX PFRH VP VQRPEX
MPUPTBOMU CRGCVFI VIRMT QESFVPXKPA MU HBSF FASWHU XQ DBZGS GLG ORIF PS
XJFVV KOUEDJGEPT  JLQ MBZG LBLNSNFKT JI JPCI VINX VIVW ISREV ORAU XVPN IRPR
UB WGDHVG UUI YPEPF QREEF
CVGTF EIFAGA NNCDF


5. The Mystery of Mekka

Mohammed said: "When the clock starts to strike six o'clok wherever you are you should kneel down turning your faces towards holy places in Mekka and start to pray." And his followers spread to entire world and they did what Mohammed told them.

Once several Mohammedans met at one square at six o'clock. Nobody of them knew precisely where Mekka is. Each of them turns where he suppose Mekka to be. Then he wants to ensure himself that his direction is correct and he takes a look at the nearest Mohammedan sitting in front of him and he turns to the same direction as his fellow sits. All Mohammedans turn at the same time each second. Mohammedans who do not see any of their fellows in front of them and Mohammedans who look at the Mohammedan turned in the same direction as they are do not turn.

Task: The square is divided into MxN little squares. Each little sqaure can contain one of the following four objects: 'N','S','E','W' ('N' is a Mohammedan turned to the north,... 'W' is a Mohammedan turned to the west).

  1. Write a program which simulates the state of square for each second starting at six o'clok. The program ends when all the Mohammedans stop turning.
  2. Is it possible that some Mohammedans never stop turning? If it is possible write a program which for given square counts the number of such Mohammedans. If it is not possible, prove it.
  3. Describe the state of the square after the program in part 1 ends.
  4. Example:

      SWS       WSE       WEE
      WNE       WWE       WWE
      WSE       WSE       WSE
    
    6:00:00   6:00:01   6:00:02
    


    (C) 1997, Organizers of the CSP