Here is an interesting question that I met:
You can simply say that on the number line of length M, where 0 < M <= 1,000,000,000, you have given whole pairs of points N( 1 < N <= 100,000). In each pair, the first point represents the object in which the object is currently located, and the second point represents where the object should be moved. (Keep in mind that the point secondmay be smaller than first).
Now suppose you start from a point 0and have a cart that can hold an object 1. You want to transfer all objects from their starting positions to the corresponding end positions, moving the smallest distance along the number line (rather than the offset). You must score a point M.
Now I tried to reduce this problem to a simpler problem. Honestly, I can't even think of brute force (possibly greedy) decision. However, my first thought was to translate the reverse movement into two forward movements, but this does not work in all cases.
I took out these test cases 3in
: 12. red 0. 6 (distance = 6), red, green. 5 (distance = 1) green. 6 (distance = 1) red, , 9 (distance = 3), 10 (distance = 1), .
6 + 1 + 1 + 3 + 1 = 12, .
12, . .
- ?