XI Olympiad in Informatics 2003/2004

Zadanie: MIS

Pooh-Eeyore-sticks

III stage competition (national finals), day I  
Source file: mis.*
Memory limit: 32 MB

Bolek and Lolek are playing a game known under a familiar name of Pooh-Eeyore-sticks. To play Pooh-Eeyore-sticks only some poohsticks and just as indefinite number of eeyoresticks are necessary. All the sticks, both poohsticks and eeyoresticks, form together the game pool. It is also necessery to choose an arbitrary (positive) integer, traditionally called the PE-bound.
Bolek moves first and can thus remove a certain positive number of poohsticks or eeyoresticks from the game pool. He can also remove both poohsticks and eeyoresticks at once, provided that he picks the same positive number of poohsticks and eeyoresticks. Obviously, he may not pick more poohsticks nor eeyoresticks than there are in the pool. Moreover, neither the number of poohsticks nor eeyoresticks taken away may be greater than the PE-bound.
Subsequent moves are made in turns according to the same rules. The player who first empties the game pool is the winner. Help Bolek prevail against Lolek!

Task

Your task is to write a module that will play as Bolek after being compiled with another playing programme. You will be given a simplified playing programme, so that you will able to test your solution. Your module should contain the following two procedures (functions):

Your module may not open any files nor use the standard input / output. Should your programme make an illegal operation, e.g. the procedure ruch_bolka returns an illegal (inconsistent with game rules) move, it shall be immediately terminated and you will receive 0 points for the test. If your programme loses the game, you will be given 0 points for the test as well. If it wins however, you will be given the maximum number of points allocated for the test. In each test your programme is going to receive, Bolek can win, no matter what moves Lolek makes.

Files (Pascal)

In the directory mis_pas you will find the following files:

Files (C / C++)

In the directory mis_c / mis_cpp you will find the following files:

Solution

As a result of your work you should present only one file: either mis.c, or mis.cpp or mis.pas, no more.

Example

This is a sample course of the game:
Call
Description
poczatek(7, 2, 3);there are 7 Poohsticks, 2 Eeyoresticks, and PE-bound=3
ruch_bolka (7, 2, bp, be); or
ruch_bolka (7, 2, &bp, &be);
first move
Bolek removes 1 poohstick and 1 eeyorestick from the pool; 6 poohsticks and 1 eeyorestick remain
ruch_bolka (3, 1, bp, be); or
ruch_bolka (3, 1, &bp, &be);
Lolek removed 3 poohsticks from the pool; 3 poohsticks and 1 eeyorestick remain
Bolek picks 1 poohstick; 2 poohsticks and 1 eeyorestick remain
ruch_bolka (1, 0, bp, be); or
ruch_bolka (1, 0, &bp, &be);
Lolek picks 1 poohstick and 1 eeyorestick; 1 poohstick and no eeyorestick remain
Bolek removes the final poohstick from the pool and thus wins