A "Microsoft Face Test" was discussed with the leader of Weibo at dinner.

Source: Internet
Author: User

Quote is because I do not know whether it is really Microsoft face test questions. The title is this:

There is a car on an infinite road, its starting position and unit time speed are finite large integer (positive and negative uncertainty), the existing instrument, in each time unit can be detected 1 times whether the car in the specified position, to find a method can be in a limited time to find out the speed and the initial position.

Answer Yue:

To solve this problem is divided into two steps, the first step to detect the car once

The second step is to find out the speed and displacement of the vehicle.

The first step is to answer

Obviously, if the vehicle is shifted to s and the velocity is V, the position of the vehicle in time t must be s+v*t

Now I am in time t, can make a guess to <s,v> value <x,y>, and then detect position x+y*t, if this position has a car, then the first step to be solved, if this position does not have a car, it must indicate that guess <x,y> is incorrect, can eliminate the solution <x,y>

So now we're going to construct a sequence <x (t), Y (t), so that for any <s,v> value, there is always a finite number of t so that the <x (t), Y (t) > value is <s,v> The geometric meaning of this problem is to map all the points in a plane to a sequence, and the following is one of the easiest solutions to be programmed. (I'm talking about a spiral map when I'm eating, but I think it's not as easy as a diamond map to be programmed)

Assuming that the sum of S and V is M, then M is bound to be finite, and can now be detected using the algorithm shown in the following code:

var t = 0;
for (var m = 0; m < Infinity; m++) {

for (var x = 0; x <= m x + +) {
var y = m-x;

if (check (x+y* (t++)) {
Break
}
if (check (x+-y) * (t++)) {
Break
}
if ((x) +y* (t++)) {
Break
}
if (check (-X) + (-y) * (t++)) {
Break
}

}

}
I know you will want to hit me after reading the code, yes, in front of that pile of nonsense is actually said that the simple thing ...

A second step,

Since the first step of the assumption <x,y> is not a necessary condition for the position, it is not possible to reverse the probe hit vehicle after <s,v> must be <x,y>. But we know the current position of the car, the speed of the car can be x, according to 0,1,-1,2,-2,3,-3 ... such a sequence of guesses, the second hit can get Speed v.

The initial position can be calculated from the velocity


From:http://www.cnblogs.com/winter-cn/archive/2012/07/08/2581790.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.