Note that there are some explanatory texts on larger screens.

plurals
  1. POVisiting points, algorithm
    primarykey
    data
    text
    <p>I'm learning for the exam from algorithms and data structures (that I have in a month) and I can't manage with finding efficient algorithm for this problem:</p> <blockquote> <p>We are given 1 &lt;= n &lt;= 5000 points on the line. Each point has different natural coordinate 0 &lt;= d &lt;= 10^6 and (not necessarily different) natural <strong>point-time</strong> 0 &lt;= t &lt;= 10^9 in seconds. We can start at any point and in each second change our current coordinate by +/-1. The problem is to visit all the points in such order that every point is visited before elapsing his point-time. Find the minimum total time (in seconds) of this trip, or say it's impossible.</p> </blockquote> <p>For example, 5 points given (coordinate, point-time):</p> <p>(1,3), (3,1), (5,6), (8,19), (10,15), it's possible, when we take a trip visiting coordinates: 3 -> 1 -> 5 -> 8 -> 10, we got minimum total time, which is equal to: 11.</p> <p>My first idea was to sort all the points lexicographically by: (point-time, coordinate), and then visit them in this order. Of course, when there are points between i-th point and (i+1)-th point, we can visit them before visiting (i+1)-th point. But unfortunately, there is no argument why such greedy approach should work, despite the fact that it would be difficult to implement. Maybe I'm trying to solve it too quickly? n is small so, O(n^2) should be ok, I suppose.</p> <p>I found other examples of the input, thinking maybe it will help me finding the solution. But now I only see that I have to find one permutation of all possible $n!$ permutations.</p> <p><strong>Input examples:</strong></p> <p>points (also given by coordinate, point time respectively): (0,4), (1,2), (4,5): surprisingly (I think) we have to visit them: 0 -> 1 -> 4, because any different order does not satisfy condition in one before last sentence in problem text.</p> <p>points: (0,7), (1,2), (2,1), (3, 4), (4,11), the only funny way is: 2 -> 1 -> 3 -> 0 -> 4, which takes us 10 seconds.</p> <p>Can anyone help?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload