当前位置:网站首页>User scheduling problem
User scheduling problem
2022-06-25 17:42:00 【Python Encyclopedia】
■ Title Description
A positive integer array is given to represent the task list to be executed by the system , Each element of the array represents a task , The value of the element indicates the type of the task .
Please calculate the minimum time required to complete all tasks .
The task execution rules are as follows :
Tasks can be executed in any order , And the execution time of each task is 1 Time units .
Two tasks of the same type must have a length of N Cooling time of units , such as N by 2 when , In time K Type executed 3 The task of , that K+1 and K+2 Two time cannot execute type 3 Mission .
The system can perform a task in any unit of time , Or waiting state .
explain : The maximum length of the array is 1000, Maximum speed 1000.
Input description
The first line records an array separated by half width commas , Array length not more than 1000, The value of the array element does not exceed 1000,
The second line records the task cooling time ,N As a positive integer ,N<=100.
Output description
The output is the minimum time required to complete all tasks .
Example 1 Input and output examples are for debugging only , The background judgment data generally does not contain examples
Input
2,2,2,3
2
Output
7
explain
Time 1: Execution type 2 Mission .
Time 2: Execution type 3 The task of ( Because the cooling time is 2, So time 2 Cannot execute type 2 The task of ).
Time 3: The system waits ( Still in type 2 The cooling time of ).
Time 4: Execution type 2 Mission .
Time 5: The system waits .
Time 6: The system waits .
Time 7: Execution type 2 Mission .
So it takes a total of 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())
边栏推荐
猜你喜欢
How Jerry used to output a clock source to the outside world [chapter]
杰理之增加加密文件播放功能【篇】
有关均衡----简易版瓶颈模型
What are the steps for launching the mobile ERP system? It's important to keep it tight
How does LSF see whether the job reserved slot is reasonable?
揭秘GES超大规模图计算引擎HyG:图切分
学习太极创客 — MQTT(二)MQTT 基本原理
How high does UART baud rate require for clock accuracy?
【编译原理】概述
Jerry's system clock setting is reset or invalid [chapter]
随机推荐
Treasure and niche Chinese painting 3D texture material website sharing
HMS core machine learning service realizes simultaneous interpretation, supports Chinese-English translation and multiple voice broadcast
观察者模式之通用消息发布与订阅
求满足条件的最长子串长度
相同wifi下,笔记本连接台式机上的虚拟机
数学建模——线性规划
Learn Tai Chi Maker - mqtt (III) connect to mqtt server
启牛涨乐财付通下载是可以开户吗?开户安全吗
[matlab] data interpolation
【编译原理】概述
Operating steps for installing CUDA in win10 (continuous improvement)
智能对话01-redis的安装
【UVM实战 ===> Episode_2 】~ VIP、VIP的开发、VIP的发布
Essential characteristics of convolution operation +textcnn text classification
Interrupt operation: abortcontroller learning notes
启牛的涨乐财付通如何?安全靠谱吗
Vscode automatically generates ifndef define ENDIF of header file
Precautions for the use of Jerry's wake-up mouth [chapter]
SDN system method | 10 The future of SDN
【UVM实战 ===> Episode_1 】~ MCDF设计更新、AMBA标准接口、UVM验证环境更新