我想为两个列表中的公司之间的快速会议创建一个时间表:一侧有 10 个“A”公司,另一侧有 20 个“B”公司。
规则如下:
我无法专心致志地让这件事发生......有什么帮助吗?
我无法创建召开这些会议的时间表。
我已经测试过并且有效。希望能帮到你。
def generate_meeting_schedule(A_companies, B_companies, time_slot_duration=10):
total_meetings = len(A_companies) * len(B_companies)
if total_meetings % len(A_companies) != 0:
raise ValueError("Number of A companies and B companies should allow for an equal number of meetings.")
schedule = []
start_time = 900 # 9:00 AM
for i in range(total_meetings // len(A_companies)):
time_slot = {
'start_time': start_time + (i * time_slot_duration),
'end_time': start_time + (i * time_slot_duration) + time_slot_duration,
'meetings': [(A_companies[j], B_companies[(j + i) % len(B_companies)]) for j in range(len(A_companies))]
}
schedule.append(time_slot)
return schedule
def print_meeting_schedule(schedule):
for i, slot in enumerate(schedule, start=1):
print(f"Time Slot {i}: {slot['start_time'] // 100}:{slot['start_time'] % 100:02d} - "
f"{slot['end_time'] // 100}:{slot['end_time'] % 100:02d}")
for A_company, B_company in slot['meetings']:
print(f"- {A_company} meets {B_company}")
print("---------------------------------------")
测试部分:
A_companies = [f"A{i}" for i in range(1, 11)]
B_companies = [f"B{i}" for i in range(1, 21)]
try:
schedule = generate_meeting_schedule(A_companies, B_companies)
print_meeting_schedule(schedule)
except ValueError as e:
print("Error:", e)