抓间谍(离散直线)
Catching the Spy
题目详情
一名间谍在整数直线上运动。时刻 0 在位置 ,之后每个整数时刻向右移动 ( 可为负,即向左)。 是固定整数但你不知道。
你每个时刻(从 0 开始)可以选择一个整数位置并询问“间谍是否此刻在该位置?”,得到是/否。
问:是否存在一种询问策略,保证最终一定能抓到间谍?若有,请给出思路。
提示:整数对 可数,可以枚举。
A spy is located on a one-dimensional line. At time 0, the spy is at location A. With each time interval, the spy moves B units to the right (if B is negative, the spy is moving left). A and B are fixed integers, but they are unknown to you. You are to catch the spy. The means by which you can attempt to do that is: at each time interval (starting at time 0), you can choose a location on the line and ask whether or not the spy is currently at that location. That is, you will ask a question like "Is the spy currently at location 27?" and you will get a yes/no answer. Devise an algorithm that will eventually find the spy
解析
可以保证抓到。
关键:所有整数对 可数,存在一个枚举 覆盖所有可能。
在时刻 ,你询问位置
若真实参数为 ,则它会在某个 上被枚举到:。此时询问的位置恰好等于间谍当时位置,于是回答为“是”,即可抓到。
Original Explanation
Solution
Here is a detailed solution with images
And here is a short solution:
Since integer 2-tuples are countable, there exists a function such that covers all integer 2-tuples.
Let . The algorithm will be to check for location at time instant .
Given and , there exists such that , and thus at time instant we will be checking for location which is - the actual location of the spy.