Python Forum
Settle the tourists into their rooms
Thread Rating:
  • 2 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Settle the tourists into their rooms
#9
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 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.
Reply


Messages In This Thread
InterstingTask - by Katenn - Sep-30-2020, 10:01 PM
RE: InterstingTask - by Gribouillis - Oct-01-2020, 11:47 AM
RE: InterstingTask - by Katenn - Oct-01-2020, 12:03 PM
RE: InterstingTask - by perfringo - Oct-01-2020, 12:11 PM
RE: InterstingTask - by Gribouillis - Oct-01-2020, 02:04 PM
RE: Settle the tourists into their rooms - by Gribouillis - Oct-05-2020, 05:32 PM
Settle the tourists into their rooms - by Katenn - Oct-04-2020, 07:55 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020