QOJ.ac

QOJ

时间限制: 1 s 内存限制: 256 MB 总分: 100 交互

#11888. Teddy Bears

统计

Bolek and Lolek are playing a game with the homey-sounding name "misie-patysie" (teddy bears and sticks). To play, you need some number of teddy bears and an equally indefinite number of sticks, which together form the game pool. You must also choose any natural number, which by tradition is called the MP-limit.

The first move belongs to Bolek, who can take a certain positive number of teddy bears or sticks from the pool. He can also take both teddy bears and sticks at the same time, but only if he takes the same number of each, and that number is greater than zero. Of course, one cannot take more teddy bears than are in the pool — the same applies to sticks. Furthermore, one cannot take more of either than the MP-limit.

Subsequent moves are performed alternately according to the same rules. The winner is the player after whose move the pool remains empty. Your goal is to help Bolek win against Lolek.

The task is to write a module that, when compiled with the appropriate game-playing program, will play as Bolek. For the purposes of this task, you will receive a simplified game-playing program that will allow you to test your solution. Your module should contain the following two procedures (functions):

  • procedure poczatek (m, p, mpo : LongInt) or void poczatek (int m, int p, int mpo) This procedure (function) will be called only once, at the beginning of the game. You can use it to initialize variables or data structures needed during the game. The parameters m, p, and mpo contain the number of teddy bears and sticks in the game pool and the MP-limit, respectively. The number of teddy bears and sticks in the pool will always be positive and no greater than $10^7$. The MP-limit will be positive and no greater than $10^6$.

  • procedure ruch_bolka (m, p : LongInt; var bm, bp : LongInt) or void ruch_bolka (int m, int p, int *bm, int *bp) This procedure (function) should determine Bolek's next move. The parameters m and p passed to it contain the number of teddy bears and sticks remaining in the game pool after Lolek's last move, respectively. The values of the parameters passed during the first call to the ruch_bolka procedure (function) are the same as the corresponding values of the parameters passed to the poczatek procedure (function). Before the procedure finishes execution, the variables bm, bp (*bm and *bp in C/C++) should contain the number of teddy bears and sticks taken by Bolek from the pool, respectively.

Your module must not open any files or use standard input/output. If your program performs an unauthorized operation, including, for example, if the ruch_bolka procedure returns a move inconsistent with the rules of the game, its execution will be terminated. In this case, you will receive 0 points for the given test.

If your program loses the game, you will receive 0 points for the test. If it wins, you will receive the maximum number of points provided for the given test. For every test on which your program is run, Bolek can win, regardless of Lolek's moves.

Available files

Pascal

In the mis_pas directory, you will find the following files: mis.pas – a skeleton of the playing module containing empty poczatek and ruch_bolka procedures. You should write the code for these procedures. graj.pas – a simplified program that generates the game. Lolek's moves are performed according to a very simple strategy, while Bolek's moves are determined by calling the procedures of the mis.pas module. You can use this program to test your playing module.

C/C++

In the mis_c/mis_cpp directory, you will find the following files: mis.h – a file containing the headers for the poczatek and ruch_bolka functions. mis.c/mis.cpp – a skeleton of the playing module containing empty definitions of the functions declared in the mis.h header file. You should write the code for these functions. * graj.c/graj.cpp – a simplified program that generates the game. Lolek's moves are performed according to a very simple strategy, while Bolek's moves are determined by calling the procedures of the mis.c/mis.cpp module. You can use this program to test your playing module.

Examples

Input 1

poczatek(7, 2, 3);
ruch_bolka(7, 2, bm, bp);
ruch_bolka(3, 1, bm, bp);
ruch_bolka(3, 1, bm, bp);
ruch_bolka(1, 0, bm, bp);
ruch_bolka(1, 0, bm, bp);

Output 1

// Initial state: 7 teddy bears, 2 sticks, MP-limit=3
// Bolek takes 1 teddy bear and 1 stick; 6 teddy bears and 1 stick remain
// Lolek takes 3 teddy bears; 3 teddy bears and 1 stick remain
// Bolek takes 1 teddy bear; 2 teddy bears and 1 stick remain
// Lolek takes 1 teddy bear and 1 stick; 1 teddy bear and 0 sticks remain
// Bolek takes 1 teddy bear and wins

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.