Python任务最优调度

B站影视 电影资讯 2025-03-20 22:20 3

摘要:def least_interval(tasks, n):from collections import Counterimport heapq# 统计每个任务的出现次数task_counts = Counter(tasks)max_heap = [-cnt

def least_interval(tasks, n):from collections import Counterimport heapq# 统计每个任务的出现次数task_counts = Counter(tasks)max_heap = [-cnt for cnt in task_counts.values]heapq.heapify(max_heap)time = 0while max_heap:temp = for _ in range(n + 1):if max_heap:temp.append(heapq.heappop(max_heap))for cnt in temp:if cnt + 1

来源:小周科技论

相关推荐