当前位置:网站首页>用户调度问题
用户调度问题
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())
边栏推荐
- 内卷?泡沫?变革?十个问题直击“元宇宙”核心困惑丨《问Ta-王雷元宇宙时间》精华实录...
- Singleton mode application
- Why does MySQL limit affect performance?
- Babbitt yuan universe daily recommendation: three players holding "tens of millions" of collections have revealed the "three routines" of the digital collection market
- WPF开发随笔收录-心电图曲线绘制
- FreeRTOS内核时钟不对的问题解决
- [efficiency] another note artifact is open source!
- Assembly language (6) uses JCC instructions to construct branches and loops
- 2022云的世界会更好吗
- 剑指 Offer II 014. 字符串中的变位词 滑动窗口
猜你喜欢

上线移动ERP系统有哪些步骤?环环紧扣很重要

【Matlab】数据插值

【编译原理】词法分析

WPF development essays Collection - ECG curve drawing

try with resource

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

Solution to the problem of incorrect clock in FreeRTOS kernel
![[untitled]](/img/14/ec21953b76a6a7bb1e692e08001571.png)
[untitled]

CVPR small target detection: context and attention mechanisms improve small target detection (attached with paper Download)

社交电商如何运营推广?
随机推荐
相同wifi下,笔记本连接台式机上的虚拟机
软考中级和高级选哪个比较好?
College Students' hot summer exchange, Rog star product phantom 16 flipped version / phantom 13 / phantom x appointment
Learn Tai Chi Maker - mqtt (III) connect to mqtt server
剑指 Offer II 012. 左右两边子数组的和相等
XXIX - orbslam2 real-time 3D reconstruction using realsensed435
Automatic submission for the next education day
Redis系列——概述day1-1
剑指 Offer II 025. 链表中的两数相加
Xshell connecting VMware virtual machines
Why are there few embedded system designers in the soft test?
Are these old system codes written by pigs?
【编译原理】概述
芝士糖豆打造AR潮玩新体验
2021年5月云南省网络空间安全比赛赛题复盘
Mathematical modeling - linear programming
Tensorflow old version
What are the steps for launching the mobile ERP system? It's important to keep it tight
redis 分布式锁整理
2022云的世界会更好吗