假设有n个收银员进行货币兑换,此刻,第i个收银员面前有ki人数。现在,排在第i个收银员行中的第j个人有m [i,j]个笔记。我们必须找到一个人可以多早交换他/她的笔记。我们要记住,收银员花了5秒钟来扫描一张钞票,在完成对客户的每张钞票的扫描后,他/她花了15秒钟来交换钞票。
因此,如果输入类似于Input:n = 6,则k = [12,12,12,12,12,12,12]
7 | 8 | 9 | 7 | 9 | 6 | 10 | 9 | 9 | 6 | 7 | 8 |
10 | 7 | 10 | 9 | 8 | 9 | 9 | 9 | 9 | 6 | 5 | 6 |
9 | 8 | 8 | 9 | 8 | 6 | 7 | 9 | 10 | 6 | 6 | 7 |
7 | 6 | 9 | 6 | 6 | 9 | 8 | 9 | 6 | 6 | 8 | 9 |
9 | 8 | 7 | 6 | 5 | 10 | 8 | 10 | 7 | 6 | 6 | 8 |
8 | 7 | 6 | 5 | 7 | 9 | 7 | 9 | 6 | 5 | 5 | 7 |
则输出为585,因为收银员需要5秒钟来扫描每个客户的每张钞票,所以加5 * m [I,j]。现在,每个收银员为每个客户花费15秒,因此将15 * k []添加到答案中。在计算每个收银员花费的时间之后所花费的最短时间将成为答案。因此,出纳员m [5]花费最短时间585。
为了解决这个问题,我们将遵循以下步骤-
n:= k的大小
最低:= 99999
对于0到n范围内的i,执行
最低:=温度
温度:=温度+ m [i,j] * 5
温度:= k [i] * 15
对于范围为0至k [i]的j,
如果temp <最小值,则
最低回报
让我们看下面的实现以更好地理解-
def minTimeToExchange(k, m): n = len(k) minimum = 99999 for i in range(n): temp = k[i] * 15 for j in range(k[i]): temp += m[i][j] * 5 if temp < minimum: minimum = temp return minimum k = [12, 12, 12, 12, 12, 12] m = [ [7,8,9,7,9,6,10,9,9,6,7,8], [10,7,10,9,8,9,9,9,9,6,5,6], [9,8,8,9,8,6,7,9,10,6,6,7], [7,6,9,6,6,9,8,9,6,6,8,9], [9,8,7,6,5,10,8,10,7,6,6,8], [8,7,6,5,7,9,7,9,6,5,5,7]] print(minTimeToExchange(k, m))
[12, 12, 12, 12, 12, 12], [[7,8,9,7,9,6,10,9,9,6,7,8], [10,7,10,9,8,9,9,9,9,6,5,6], [9,8,8,9,8,6,7,9,10,6,6,7], [7,6,9,6,6,9,8,9,6,6,8,9], [9,8,7,6,5,10,8,10,7,6,6,8], [8,7,6,5,7,9,7,9,6,5,5,7]]
输出结果
585