#P7135. 小 B 的面包

    ID: 8039 远端评测题 1000ms 256MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>搜索贪心交互题Special Judge博弈树

小 B 的面包

Background

This problem is a functional interactive problem.

Little B has obtained a lot of bread, and Little Y is very angry and wants to take the bread away.

Little Y proposes to play an interesting game with Little B. If Little B loses, all of Little B’s bread will be taken away.

Little B also needs to take a walk by the river at 【data deletion】, so he hands this task over to you.

Can you, the smart one, help Little B protect his precious bread?

Problem Description

It is recommended to use c++ for this problem.

Little Y places 99 pieces of bread on the table in order. The ii-th piece has mass ii.

Little Y and you take turns choosing bread. Whoever is the first whose chosen bread contains some three pieces whose total mass is exactly 1515 wins, and the other loses. Each piece of bread can be taken only once: once one player takes a piece, the other player cannot choose it anymore, and after choosing, it cannot be put back.

If in the end all bread is taken and neither side reaches the condition, it is a draw.


In this problem, you need to implement, and only need to implement, the following three functions (you may call or access your own helper functions or global variables inside them):

extern "C" int choose(int x);
extern "C" void init();
extern "C" void newgame(bool f);
/* Note: the extern "C" before the three functions above must not be omitted. */

During judging, the interaction library will first call the init() function you implement once. The purpose of init() is to let you do initialization at the very beginning. It will not be called again later. If you do not need initialization, you still must include extern "C" void init() {}.

Next, the interaction library will call the newgame(bool f) function you implement. Calling newgame(bool f) means a new game starts. If the passed-in f equals 11, the interaction library chooses first; otherwise, you choose first.

Then the interaction library will repeatedly call your choose(int x) function. The input xx indicates that Little Y has chosen the xx-th piece of bread. After this function finishes, you need to return an integer y(1y9)y(1 \le y \le 9) indicating that you choose the yy-th piece of bread, i.e.:

extern "C" int choose(int x) { /* x is the bread chosen by the interaction library */
    /* your code */
    return y; /* y is the bread chosen by you */
}

In particular, when x=0x=0 is passed in, it means you choose bread first. If your choose(int x) function returns an invalid value, the game ends immediately, and the interaction library is considered the winner.

The choose(int x) function will be called continuously until one side wins or it is a draw, i.e. the game ends. After that, the interaction library will call newgame(bool f) again to start another new game. In total, the interaction library will call newgame(bool f) 18001800 times, meaning 18001800 games will be played.

For details, see template_game.cpp.


In the additional files, there is the following file:

template_game.cpp — you will implement the three functions above in this file. It contains detailed comments and also includes reference code for the interaction library. Please read it carefully. It is recommended to solve the problem based on this template.

You can compile it directly in your IDE locally.

Input Format

None.

Output Format

For the local interaction library, the interaction library will output two lines at the end:

The first line contains two numbers w,dw,d, representing the number of games you win and the number of draws.

The second line is your score.

Hint

It is guaranteed that the interaction library uses a completely random selection strategy, i.e. each time it selects uniformly at random from the bread that has not been chosen yet.

Among the 18001800 games, there are 600600 games where your program chooses first, and 12001200 games where the interaction library chooses first.

Specifically, for the ii-th game, if imod3=0i \bmod 3 = 0, then your program chooses first; otherwise, the interaction library chooses first.

This problem is first subject to the same constraints as traditional problems. For example, a compilation error will cause the whole problem to get 00 points; a runtime error, exceeding the time limit, exceeding the memory limit, etc., will cause the corresponding test point to get 00 points, and so on.

You may only access variables defined by yourself and those provided by the interaction library, as well as their corresponding memory space. Attempting to access other space may cause compilation errors or runtime errors.

This problem has only one test point, and your score is judged as follows:

Suppose your program wins xx games and draws yy games. Your final score is represented by the scoring function f(x,y)f(x,y):

$$f(x,y)=\lfloor (\frac{x+y}{6}-200) \cdot \min((\frac{x}{x + y})^2+0.2,1) \rfloor$$

The minimum score is 00.

The actual interaction library used in judging is different from the one provided. Your program should not depend on the implementation of the interaction library.

For details, see template_game.cpp.

Translated by ChatGPT 5