当前位置:网站首页>用户调度问题
用户调度问题
2022-06-25 17:11:00 【Python知识大全】
■ 题目描述
给定一个正整数组表示待系统执行的任务列表,数组的每一个元素代表一个任务,元素的值表示该任务的类型。
请计算执行完所有任务所需的最短时间。
任务执行规则如下:
任务可以按任意顺序执行,且每个任务执行耗时间均为1个时间单位。
两个同类型的任务之间必须有长度为N个单位的冷却时间,比如N为2时,在时间K执行了类型3的任务,那么K+1和K+2两个时间不能执行类型3任务。
系统在任何一个单位时间内都可以执行一个任务,或者等待状态。
说明:数组最大长度为1000,速度最大值1000。
输入描述
第一行记录一个用半角逗号分隔的数组,数组长度不超过1000,数组元素的值不超过1000,
第二行记录任务冷却时间,N为正整数,N<=100。
输出描述
输出为执行完所有任务所需的最短时间。
示例1 输入输出示例仅供调试,后台判题数据一般不包含示例
输入
2,2,2,3
2
输出
7
说明
时间1:执行类型2任务。
时间2:执行类型3的任务(因为冷却时间为2,所以时间2不能执行类型2的任务)。
时间3:系统等待(仍然在类型2的冷却时间)。
时间4:执行类型2任务。
时间5:系统等待。
时间6:系统等待。
时间7:执行类型2任务。
因此总共耗时7。
def task_schedule():
arr = input().strip().split(",")
n = int(input().strip())
d = {
}
d_max = 0
d_max_n = 0
for i in arr:
d[i] = d.get(i, 0) + 1
if d[i] > d_max:
d_max = d[i]
for k, v in d.items():
if d[k] == d_max:
d_max_n += 1
return max((d_max - 1) * (n + 1) + d_max_n, len(arr))
if __name__ == "__main__":
print(task_schedule())
边栏推荐
猜你喜欢

Super Full Metal PBR Multi - channel Mapping Materials website collation

Website arrangement of super all metal PBR multi-channel mapping materials

What are the steps for launching the mobile ERP system? It's important to keep it tight

Why are there few embedded system designers in the soft test?

Xshell connecting VMware virtual machines

项目经理在项目中起到的作用

Why does MySQL limit affect performance?

Treasure and niche Chinese painting 3D texture material website sharing

Uncover ges super large scale graph computing engine hyg: Graph Segmentation

Vscode plug-in self use
随机推荐
How smart PLC constructs ALT instruction
mood
Design and arrangement of DDIA data intensive application system
大学生暑假换机热,ROG 明星产品幻 16 翻转版 / 幻 13 / 幻 X 预约
Next. JS hot update markdown file change
中断操作:AbortController学习笔记
学习太极创客 — MQTT(三)连接MQTT服务端
Knowing these interview skills will help you avoid detours in your test job search
WPF开发随笔收录-心电图曲线绘制
上线移动ERP系统有哪些步骤?环环紧扣很重要
记一次基于PHP学生管理系统的开发
Kotlin
Next.js 热更新 Markdown 文件变更
The role of the project manager in the project
相同wifi下,笔记本连接台式机上的虚拟机
Interrupt operation: abortcontroller learning notes
Snakeyaml profile parser
【Matlab】曲线拟合
The art of code annotation. Does excellent code really need no annotation?
PSYNC command of redis