← 返回 scale.ai 的题目列表Party Time Duration Analysis
类型:online_judge
Given a schedule of multiple parties (each with a start time and end time), and the location information for each party (town, city, state, etc.).
For each town, calculate the total hours that are in progress for parties on that day.
Format and output periods of downtime (not engaged in party activities) grouped by city.
Input:
The party information format is a list, each containing: party_id, start_time, end_time, town, city, state.
Party times are always on the same day. Time is represented in a 24-hour format.
Output:
Total party time (hours) for each town.
Downtime periods for each city, grouped by city.
Example Input
[
{'party_id': 1, 'start_time': 10, 'end_time': 13, 'town': 'A', 'city': 'X', 'state': 'NY'},
{'party_id': 2, 'start_time': 12, 'end_time': 15, 'town': 'A', 'city': 'X', 'state': 'NY'},
{'party_id': 3, 'start_time': 9, 'end_time': 11, 'town': 'B', 'city': 'Y', 'state': 'CA'}
]
Example Output
1. {'A': 6, 'B': 2}
2. {
'X': [('0:00', '10:00'), ('15:00', '24:00')],
'Y': [('0:00', '9:00'), ('11:00', '24:00')]
}
Constraints
The party end time is always greater than the start time.
City names, town names, and state names in the input are unique.
Example
Input
[{'party_id': 1, 'start_time': 10, 'end_time': 13, 'town': 'A', 'city': 'X', 'state': 'NY'},{'party_id': 2, 'start_time': 12, 'end_time': 15, 'town': 'A', 'city': 'X', 'state': 'NY'},{'party_id': 3, 'start_time': 9, 'end_time': 11, 'town': 'B', 'city': 'Y', 'state': 'CA'}]