Oct-05-2020, 05:32 PM
(This post was last modified: Oct-05-2020, 05:32 PM by Gribouillis.)
Here is another approach: it is easy to find if there is a solution where the minimal distance between tourists is at least a given number
Then use a dichotomic algorithm. If the distance x is possible (the technical term is feasable) and the distance y is not, then if y == x + 1, x is the searched optimum, otherwise try with (x+y)//2 and replace x or y by this number.
This algorithm's complexity is about n log(n) or something similar.
x
. For this, put the first tourist in the first room with number n, then the next tourist must be at least in the first room which number is at least n+x. Continue this procedure with the remaining tourists, adding each time at least x to the last given room number until you find a solution or an impossibility.Then use a dichotomic algorithm. If the distance x is possible (the technical term is feasable) and the distance y is not, then if y == x + 1, x is the searched optimum, otherwise try with (x+y)//2 and replace x or y by this number.
This algorithm's complexity is about n log(n) or something similar.