Carlo hates bugs, he wants to kill every single one of them. After months of hard work, he successfully killed all the bugs in his garden, but when he was about to celebrate, a grasshopper jumped out of nowhere and started to annoy him.
Figure : Carlo killing the bugs.
Carlo’s garden can be represented as a square grid of length . Initially, the grasshopper is standing at the point . The grasshopper can only jump by one cell to the East or to the North, i.e. it can jump from to or but not to or . During each second, the grasshopper makes jumps. For example, if , after one second, the grasshopper can be at , but not at or .
Carlo wants to catch the grasshopper by placing traps in the garden. If the grasshopper jumps to a point where there is a trap, it will be caught and Carlo can finally celebrate. Unfortunately, he can only place one trap per second.
Figure : If , the grasshopper can arrive to by for example first jumping to and then to . In this case, if there were any traps on , or , then it would be caught.
Can you help Carlo to catch the grasshopper with at most traps?
Interaction protocol
This is an interactive task.
The contestant must implement the following function:
void solve(int n);
This function will be called exactly once, at the beginning of the interaction, and supplies the contestant with the length of the grasshopper's jump - . Inside this function, you can call the following function:
std::pair<int, int> trap(int x, int y)
This function will place a trap at the coordinate , which is not the grasshopper’s current position, and will return the new position of the grasshopper. Once you have caught the grasshopper, the execution of the program will stop.
Don't forget to include the grasshopper.h
header!
Constraints and clarifications
- .
- Carlo’s garden is a square grid of size .
- You can place at most traps.
- The interactor is adaptive, meaning that the route and final position of the grasshopper in each round will be determined based on your output.
Your program will be tested against several test cases grouped in subtasks. In order to obtain the score of a subtask, your program needs to correctly solve all of its test cases.
# | Points | Constraints |
---|---|---|
1 | 10 | |
2 | 20 | |
3 | 20 | |
4 | 20 | |
5 | 30 |
The “animals” bugs, not the “informatics” bugs. He also hates informatics bugs by the way.
Except bees, bees are cool.
This is an interactive task! The interaction presented here is just an example.
Example
solve
is called withtrap(1, 1)
returnstrap(2, 0)
sucessfully traps the grasshopper
Explanation
In this example , so the grasshopper can only jump by one cell at a time.
Initially the grasshopper is at , Carlo places a trap at .
Then the grasshopper jumps to , Carlo places a trap at .
The grasshopper can only jump to or , in both cases it will jump on a trap and Carlo can celebrate.