📜  找出可以交换笔记的最短时间

📅  最后修改于: 2021-06-26 13:41:39             🧑  作者: Mango

给定n个收银员进行货币兑换。眼下, i^{th}收银员有k_{i}在他面前的人数。这j^{th}排队的人i^{th}收银员有m_{i,j}笔记。
找到,一个人可以多早交换他的笔记。

收银员花费的时间:

  • 收银员花了5秒钟扫描一张钞票。
  • 收银员为客户扫描每张钞票后,他花了15秒钟来交换钞票。

例子:

方法:计算每个收银员的总时间,并且在所有收银员时间中获得的最短时间是理想的答案。

下面是上述方法的实现:

C++
// CPP code to find minimum 
// time to exchange notes
#include 
using namespace std;
  
// Function to calculate minimum 
// time to exchange note
void minTimeToExchange(int k[], int m[][10],
                                     int n)
{
    int min = INT_MAX;
      
    // Checking for every cashier
    for (int i = 0; i < n; i++)
    {
        // Time for changing the notes
        int temp = k[i] * 15;
          
        // Calculating scanning time
        // for every note
        for (int j = 0; j < k[i]; j++)
        {
            temp += m[i][j] * 5;
        }
          
        // If value in temp is minimum
        if (temp < min) 
            min = temp;
    }
      
    cout << min;
}
  
// Driver function
int main()
{   
    // number of cashiers
    int n = 5;
      
    // number of customers with
    // each cashier
    int k[] = {10, 10, 10, 10, 10};
      
    // number of notes with each customer
    int m[][10] = {{6, 7, 8, 6, 8, 5, 9, 8, 10, 5},
                    {9, 6, 9, 8, 7, 8, 8, 10, 8, 5},
                    {8, 7, 7, 8, 7, 5, 6, 8, 9, 5},
                    {6, 5, 10, 5, 5, 10, 7, 8, 5, 5},
                    {10, 9, 8, 7, 6, 9, 7, 9, 6, 5}};
                  
    // Calling function
    minTimeToExchange(k, m, n);
      
    return 0;
}


Java
// Java code to find minimum time to exchange
// notes
import java.io.*;
  
public class GFG {
      
    // Function to calculate minimum 
    // time to exchange note
    static void minTimeToExchange(int []k, 
                           int [][]m, int n)
    {
          
        int min = Integer.MAX_VALUE;
          
        // Checking for every cashier
        for (int i = 0; i < n; i++)
        {
            // Time for changing the notes
            int temp = k[i] * 15;
              
            // Calculating scanning time
            // for every note
            for (int j = 0; j < k[i]; j++)
            {
                temp += m[i][j] * 5;
            }
              
            // If value in temp is minimum
            if (temp < min) 
                min = temp;
        }
          
        System.out.println(min);
    }
      
    // Driver function
    static public void main (String[] args)
    {
          
        // number of cashiers
        int n = 5;
          
        // number of customers with
        // each cashier
        int []k = {10, 10, 10, 10, 10};
          
        // number of notes with each customer
        int [][]m = {
                {6, 7, 8, 6, 8, 5, 9, 8, 10, 5},
                {9, 6, 9, 8, 7, 8, 8, 10, 8, 5},
                {8, 7, 7, 8, 7, 5, 6, 8, 9, 5},
                {6, 5, 10, 5, 5, 10, 7, 8, 5, 5},
                {10, 9, 8, 7, 6, 9, 7, 9, 6, 5}};
                      
        // Calling function
        minTimeToExchange(k, m, n);
    }
}
  
// This code is contributed by vt_m.


Python3
# Python3 code to find minimum
# time to exchange notes
from sys import maxsize
  
# Function to calculate minimum
# time to exchange note
def minTimeToExchange(k, m, n):
    minn = maxsize
  
    # Checking for every cashier
    for i in range(n):
  
        # Time for changing the notes
        temp = k[i] * 15
  
        # Calculating scanning time
        # for every note
        for j in range(k[i]):
            temp += m[i][j] * 5
  
        # If value in temp is minimum
        if temp < minn:
            minn = temp
  
    print(minn)
  
# Driver Code
if __name__ == "__main__":
  
    # number of cashiers
    n = 5
  
    # number of customers with
    # each cashier
    k = [10, 10, 10, 10, 10]
  
    # number of notes with each customer
    m = [[6, 7, 8, 6, 8, 5, 9, 8, 10, 5],
         [9, 6, 9, 8, 7, 8, 8, 10, 8, 5],
         [8, 7, 7, 8, 7, 5, 6, 8, 9, 5],
         [6, 5, 10, 5, 5, 10, 7, 8, 5, 5],
         [10, 9, 8, 7, 6, 9, 7, 9, 6, 5]]
  
    # Calling function
    minTimeToExchange(k, m, n)
  
# This code is contributed by
# sanjeev2552


C#
// C# code to find minimum 
// time to exchange notes
using System;
  
public class GFG {
      
    // Function to calculate minimum 
    // time to exchange note
    static void minTimeToExchange(int []k, 
                          int [,]m, int n)
    {
          
        int min = int.MaxValue;
          
        // Checking for every cashier
        for (int i = 0; i < n; i++)
        {
            // Time for changing the notes
            int temp = k[i] * 15;
              
            // Calculating scanning time
            // for every note
            for (int j = 0; j < k[i]; j++)
            {
                temp += m[i,j] * 5;
            }
              
            // If value in temp is minimum
            if (temp < min) 
                min = temp;
        }
          
        Console.WriteLine(min);
    }
      
    // Driver function
    static public void Main (){
        // number of cashiers
        int n = 5;
          
        // number of customers with
        // each cashier
        int []k = {10, 10, 10, 10, 10};
          
        // number of notes with each customer
        int [,]m = {{6, 7, 8, 6, 8, 5, 9, 8, 10, 5},
                    {9, 6, 9, 8, 7, 8, 8, 10, 8, 5},
                    {8, 7, 7, 8, 7, 5, 6, 8, 9, 5},
                    {6, 5, 10, 5, 5, 10, 7, 8, 5, 5},
                    {10, 9, 8, 7, 6, 9, 7, 9, 6, 5}};
                      
        // Calling function
        minTimeToExchange(k, m, n);
    }
}
  
// This code is contributed by vt_m.


PHP


输出:

480

如果您希望与行业专家一起参加现场课程,请参阅《 Geeks现场课程》和《 Geeks现场课程美国》。