当前位置: 代码迷 >> 综合 >> PAT (Advanced Level) Practice 1010 Radix(Python)
  详细解决方案

PAT (Advanced Level) Practice 1010 Radix(Python)

热度:60   发布时间:2024-02-06 21:39:09.0
class Customer:def __init__(self, coming, cost):self.coming = coming  # 到来时间self.cost = cost  # 花费时间self.start = 0  # 开始服务时间def get_difference(self):return self.start - self.comingdef main():line = input().strip().split()n, k = int(line[0]), int(line[1])queue = []for i in range(n):line = input().strip().split()line[0] = line[0].split(':')coming = int(line[0][0]) * 3600 + int(line[0][1]) * 60 + int(line[0][2])if coming > 61200:continuecost = min(int(line[1]), 60) * 60queue.append(Customer(coming, cost))queue = sorted(queue, key=lambda x: x.coming)end_times = [28800 for _ in range(k)]  # 结束时间# 处理顾客业务for i in range(len(queue)):queue[i].start = max(min(end_times), queue[i].coming)t = end_times.index(min(end_times))  # 结束服务的窗口end_times[t] = queue[i].start + queue[i].cost  # 修改结束时间# 计算平均时间sum_time = 0.0for i in range(len(queue)):sum_time += queue[i].get_difference()print('0.0') if sum_time == 0 else print('%.1f' % (sum_time / len(queue) / 60), end='')if __name__ == '__main__':main()
  相关解决方案