#P6716. [CCO 2018] Gradient Descent
[CCO 2018] Gradient Descent
Description
Troy wants to play a game with you. The game uses an grid.
There are pieces (numbered from to ). The -th piece is placed at . Multiple pieces may be on the same cell.
In one second, Troy can move one piece to a vertically or horizontally adjacent cell. Troy defines the score of a cell as the minimum number of seconds needed to move all pieces to that cell. Your task is to find the minimum score among all cells on the board.
Troy will not tell you the value of or the positions of the pieces, but you may ask Troy at most questions: the score of cell .
Interactive Strategy
This is an interactive problem.
First, read three integers , representing the size of the grid and the maximum number of questions you may ask.
After reading this line, your program may ask questions about the score of (in the format ? p q), and then you will receive an integer representing the score of that cell.
Once your program determines the minimum score among all cells on the board, it should output ! Z and terminate, where is the final answer.
After outputting each line, you must flush the buffer:
- C/C++:
fflush(stdout)orcout << endl - Java:
System.out.flush() - Pascal:
flush(output)
If your output format is incorrect, or you ask more than questions, your answer will be judged incorrect.
Input Format
None
Output Format
None
1 10 90 3
1 2
1 4
1 10
5 4 170 4
2 3
2 3
4 3
5 1
Hint
Sample Explanation
For sample
| Request | Response |
|---|---|
1 10 90 |
|
? 1 3 |
9 |
? 1 7 |
11 |
? 1 4 |
8 |
! 8 |
The piece positions should be , , and , so the minimum score over the whole board is (the score of cell ).
For sample
| Request | Response |
|---|---|
5 4 170 |
|
? 2 4 |
11 |
? 1 4 |
15 |
? 3 3 |
7 |
! 7 |
The piece positions should be , , , .
Constraints
For of the testdata, , , , , , , , 。
For of the testdata, , , 。
For another of the testdata, , 。
For another of the testdata, 。
For another of the testdata, 。
For another of the testdata, 。
The spj and interactive library are included in the attached files.
Notes
Translated from Canadian Computing Olympiad 2018 Day 2 A Gradient Descent。
spj author:
Translated by ChatGPT 5
京公网安备 11011102002149号