当前位置:网站首页>用户调度问题
用户调度问题
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())
边栏推荐
- Are these old system codes written by pigs?
- 【编译原理】词法分析
- 杰理之adc_get_voltage 函数获取电压值不准【篇】
- FreeRTOS内核时钟不对的问题解决
- Will the 2022 cloud world be better
- 【微服务|Sentinel】流控规则概述|针对来源|流控模式详解<直接 关联 链路>
- Best practices for data relocation: using CDM to relocate offline Mysql to DWS
- 2022云的世界会更好吗
- WPF development essays Collection - ECG curve drawing
- 剑指 Offer II 014. 字符串中的变位词 滑动窗口
猜你喜欢
SnakeYAML配置文件解析器
汇编语言(5)寄存器(内存访问)
Sword finger offer 50 First character that appears only once
Batch --07--- breakpoint lifting
Website arrangement of super all metal PBR multi-channel mapping materials
杰理之获取复位源和唤醒的 IO 口的方法【篇】
Redis distributed lock collation
Redis系列——概述day1-1
How does LSF see whether the job reserved slot is reasonable?
UART波特率对时钟精度的要求有多高?
随机推荐
Sword finger offer 50 First character that appears only once
心情
How does LSF see whether the job reserved slot is reasonable?
try with resource
Design and arrangement of DDIA data intensive application system
Which is better for intermediate and advanced soft exam?
Treasure and niche Chinese painting 3D texture material website sharing
WPF开发随笔收录-心电图曲线绘制
[untitled]
n-queens problem
浅谈 Web 3.0
杰理之定时器使用注意事项【篇】
Learn Tai Chi Maker - mqtt (III) connect to mqtt server
SnakeYAML配置文件解析器
数据搬迁最佳实践之使用CDM搬迁线下MySQL到DWS
WPF development essays Collection - ECG curve drawing
Automatic submission for the next education day
「津津乐道播客」#386 原汤话原食:谁还不是个“白字先生”?
Good fat man takes you to learn Flink series -flink source code analysis episode I standalone startup script analysis
Old mobile phones turn waste into treasure and serve as servers