Seeking algorithm ideas!

Problem to be solved

300 sets of single-room dormitories and 300 sets of standard (double) dormitories (standard rooms can be used as single rooms). If a team comes for training, it is necessary to arrange a dormitory for them to live in for a period of time. Now we need to count the available dormitories in a certain period of time (T1-T2), and we need to take into account the overlap of time periods. How to design a database and algorithm?

Current thinking

Database design: registration form (team name, number of standard rooms, number of individual rooms, start time, end time)

  1. By counting the number of rooms that can be checked in each day during the time period (T1-T2), it is saved in an array, and then the minimum value of the array is calculated as the number of rooms that can be arranged in the time period.

  2. Among them, to find the rooms that can be checked in each day, you need to check the records that meet (start time <search time <end time). After the records are obtained, the corresponding number of rooms used per day can be obtained, and the number of available dormitories per day can be obtained.

    Is there a more efficient, simple and feasible solution for communication?

Guess you like

Origin blog.csdn.net/xiao_bin_shen/article/details/77994257