QOJ.ac

QOJ

Limite de temps : 1 s Limite de mémoire : 128 MB Points totaux : 100 Interactif

#13306. Auction

Statistiques

Alojzy and Bajtazar are playing a bidding game. The game requires a very large set of pebbles. The players take turns: first Alojzy, then Bajtazar, then Alojzy again, and so on. At any given moment in the game, two values are important: the current bid and the current size of the pile. The game starts with a bid of one pebble and an empty pile. In each turn, a player performs one of the following moves: double the bid, triple the bid, * pass.

In the case where a player passes, the entire current bid moves to the pile (this is the only way to increase the pile), and the bidding starts again with a bid of one pebble. If a player passes, the next turn belongs to their opponent (Alojzy only starts the entire game). The player who causes the pile to overflow (this happens when there are $n$ or more pebbles on the pile) loses. If, before a player's move, the total number of pebbles on the pile and in the bid reaches or exceeds $n$, that player can no longer double or triple the bid. They must pass, thereby adding the bid to the pile, which causes them to lose.

Alojzy loses very often. Bajtazar proposed an interesting challenge to him — instead of playing the bidding game himself, it is better to write programs that will play it. Unfortunately, Alojzy does not know how to program. Help him!

Write a program that will play the bidding game on behalf of Alojzy against a library written by Bajtazar.

Subtasks

In all test cases, your program will be able to win (provided it makes the appropriate moves) regardless of the library's moves. Your program will receive points for a given test only if it wins against the library.

In all tests, the condition $1 \leqslant n \leqslant 30\,000$ holds. In 50% of the test cases, the additional condition $n \leqslant 25$ holds.

Implementation Details

To use the library, you must include the following at the beginning of your program: C/C++: #include "cliclib.h" Pascal: uses pliclib;

The library provides the following functions and procedures: inicjuj — returns the number $n$. It should be used exactly once, at the very beginning of the program's execution. C/C++: int inicjuj(); Pascal: function inicjuj: longint; alojzy — informs the library about your program's move. Its only parameter is an integer $x$, which denotes the move performed: $x = 1$ means pass, $x = 2$ — doubling the bid, and $x = 3$ — tripling the bid. C/C++: void alojzy(int x); Pascal: procedure alojzy(x: longint); bajtazar — the function informs your program about the library's move. It returns a single number $x$, which denotes the move performed. Analogously to the alojzy function, $x = 1$ means pass, $x = 2$ — doubling, and $x = 3$ — tripling the bid. C/C++: int bajtazar(); * Pascal: function bajtazar: longint;

After calling the inicjuj function, you must alternately call the alojzy and bajtazar functions (in that order). Breaking the communication protocol will be treated as an incorrect answer and will result in 0 points for the given test. In this task, the use of standard input and output is forbidden. Any communication should take place only through the functions and procedures provided above. The library will terminate the program automatically after the game ends.

Examples

C/C++ Pascal Result Pile Bid Explanation
n = inicjuj(); n := inicjuj; $15$ $0$ $1$ From this moment $n = 15$.
alojzy(2); alojzy(2); $0$ $2$ Your program doubled the bid.
bajtazar(); bajtazar; $2$ $0$ $4$ The library responded by doubling the bid.
alojzy(3); alojzy(3); $0$ $12$ Your program tripled the bid.
bajtazar(); bajtazar; $1$ $12$ $1$ The library passed. 12 pebbles move to the pile, and there is only 1 pebble in the bid again.
alojzy(2); alojzy(2); $12$ $2$ Your program doubled the bid.
bajtazar(); bajtazar; $3$ $12$ $6$ The library tripled the bid.
alojzy(1); alojzy(1); $18$ $1$ The total number of pebbles on the pile and in the bid exceeded 15. Your program is forced to pass.

The above program flow is correct, but suboptimal. Your program would not receive points for this test. In particular, for $n = 15$, there is a possibility for Alojzy to win, regardless of Bajtazar's moves.

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.