QOJ.ac

QOJ

実行時間制限: 1 s メモリ制限: 128 MB 満点: 100 インタラクティブ

#16254. Naughty Child

統計

A group of children are playing a game on the lawn, having a great time. A curious passerby walks over and asks them: "Children, what game are you playing?" "There is a referee among us, and the rest are divided into two teams: the Star team has $N$ people, and the Moon team has $M$ people. If you guess correctly who the referee is, I will tell you what game we are playing." "Sure. But, you have to give me some hints, right?" "Of course. You can ask us whether someone belongs to a certain team, but you cannot ask whether someone is the referee. The Star team members you ask will always tell you the correct answer; the Moon team members will always tell you the wrong answer; and the referee will tell you the correct answer when you ask them an odd number of times, and the wrong answer when you ask them an even number of times." "Oh, I see. Can I ask questions freely?" "You are not allowed to ask anyone about themselves. For example, you cannot ask me: 'Are you in the Star team?' You also cannot ask the same person twice about the same individual. For example, if you have asked me whether Dingding is in the Star team, you cannot ask me again whether Dingding is in the Moon team. Finally, please try not to ask the same person too many questions, because they still want to continue playing and don't have time to keep answering your questions." The passerby is very clever; not only did they guess who the referee was, but they also identified which team everyone else belonged to. Why don't you give it a try?

Interaction

This is an interactive problem. Your program should interact with the testing library and must not access any files. The testing library provides three functions: GetNM, Ask, and Answer. Their roles and usage are as follows:

GetNM(N, M) must be called first to obtain the values of the positive integers $N$ and $M$ ($2 \le N+M \le 500$).

Ask(Child1, Child2, T) is used for questioning. Here, $1 \le \text{Child1}, \text{Child2} \le N+M+1$ and $\text{Child1} \neq \text{Child2}$. $T$ is either $0$ or $1$. $T=0$ represents the Star team, and $T=1$ represents the Moon team. That is, you are asking child Child1 "Is child Child2 in team $T$?". If the function returns $1$, it means child Child1 answered "Yes"; if the function returns $0$, it means child Child1 answered "No".

Answer(Ans) is used to tell the testing library your guess. The parameter Ans can be $0$, $1$, or $2$. $0$ represents the Star team, $1$ represents the Moon team, and $2$ represents the referee. You should call this procedure $N+M+1$ times consecutively, from child $1$ to child $N+M+1$, to specify the role of each child. Note that there is only one referee. After calling this procedure $N+M+1$ times, the testing library will terminate your program. Remember that your program must not terminate on its own.

Examples

Function Call Return Value Description
GetNM(N, M) $N=1, M=1$ The Star team and Moon team each have one member
Ask(1, 2, 0) $0$ Ask child 1: "Is child 2 in the Star team?" Answer: "No"
Ask(2, 1, 0) $1$ Ask child 2: "Is child 1 in the Star team?" Answer: "Yes"
Ask(3, 1, 1) $0$ Ask child 3: "Is child 1 in the Moon team?" Answer: "No"
Answer(2) None Child 1 is the referee.
Answer(1) None Child 2 is in the Moon team.
Answer(0) None Child 3 is in the Star team.

Implementation Details

For Pascal Programmers

Your program should use the following statement to reference the testing library: uses childlib; The function/procedure prototypes provided by the testing library are: procedure GetNM(var N, M: integer); function Ask(Child1, Child2, T: integer): integer; procedure Answer(Ans: integer);

For C/C++ Programmers

You should create a project, include the file childlib.o, and add the following line to the beginning of your program: #include "childlib.h" The function prototypes provided by the testing library are: void GetNM(int *N, int *M); int Ask(int Child1, int Child2, int T); void Answer(int Ans);

Subtasks

If your program meets any of the following conditions, it will receive $0$ points: Accessed any file (including temporary files) or terminated on its own; Illegal call to library functions; * Caused the testing library to exit abnormally.

Otherwise, your score for each test case is calculated as follows: 1. You only correctly guessed who the referee is but did not correctly identify the teams of all other children. In this case, if you asked any child three or more (including three) questions, you can only get $40\%$ of the points; otherwise, you can get $60\%$ of the points. 2. You correctly guessed who the referee is and the teams of all other children. In this case, if you asked any child three or more (including three) questions, you can only get $70\%$ of the points; otherwise, you will receive full marks for that test case.

Note

How to test your program

  1. Create a text file child.in in the working directory. The first line contains two integers $N$ and $M$. The second line contains $N+M+1$ numbers (values $0, 1, 2$), where the $k$-th number is the team of child $k$ ($0$ for Star team, $1$ for Moon team, $2$ for referee). Sample input files are provided in the user directory.
  2. Execute your program, and the testing library will generate an output file child.log.
  3. If the program terminates normally, the first line of child.log contains an integer $P$, which is the maximum number of times any child was asked (counts exceeding $10$ are treated as $10$). The second line contains $N+M+1$ numbers, which are your program's guesses for each child's role. If the program exits illegally, child.log will record: "Abnormal Termination".
  4. Execute the program check in the working directory to see your score on the screen.

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.