Dado n número de cajeros intercambiando el dinero. En este momento, el cajero tenía varias personas frente a él. La persona en la fila del cajero tenía notas.
Encuentre, qué tan temprano puede uno intercambiar sus notas.
Tiempo que tardan los cajeros:
- El cajero tardó 5 segundos en escanear un solo billete.
- Después de que el cajero escaneara cada billete para el cliente, tardó 15 segundos en intercambiar los billetes.
Ejemplos:
Entrada: n = 5
k[] = 10 10 10 10 10
m1[] = 6 7 8 6 8 5 9 8 10 5
m2[] = 9 6 9 8 7 8 8 10 8 5
m3[] = 8 7 7 8 7 5 6 8 9 5
m4[] = 6 5 10 5 5 10 7 8 5 5
m5[] = 10 9 8 7 6 9 7 9 6 5
Salida: 480
Explicación: El cajero tarda 5 segundos por cada billete de cada cliente , por lo tanto suma 5*m[i][j]. Cada cajero dedica 15 segundos a cada cliente, por lo tanto, agregue 15*k[] a la respuesta. El tiempo mínimo obtenido después de calcular el tiempo que tarda cada cajero es nuestra respuesta. El cajero m4 toma el tiempo mínimo, es decir, 480.
Entrada: n = 1
k[] = 1
m1[] = 100
Salida: 515
Planteamiento: Calcular el tiempo total de cada cajero y el tiempo mínimo obtenido entre todos los tiempos de cajero es la respuesta deseada.
A continuación se muestra la implementación del enfoque anterior:
C++
// CPP code to find minimum // time to exchange notes #include <bits/stdc++.h> 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
<?php // PHP code to find minimum // time to exchange notes // Function to calculate minimum // time to exchange note function minTimeToExchange($k, $m, $n) { $min = PHP_INT_MAX; // Checking for every cashier for ( $i = 0; $i < $n; $i++) { // Time for changing the notes $temp = $k[$i] * 15; // Calculating scanning time // for every note for ($j = 0; $j < $k[$i]; $j++) { $temp += $m[$i][$j] * 5; } // If value in temp is minimum if ($temp < $min) $min = $temp; } echo $min; } // Driver Code // number of cashiers $n = 5; // number of customers with // each cashier $k = array(10, 10, 10, 10, 10); // number of notes with // each customer $m = array(array(6, 7, 8, 6, 8, 5, 9, 8, 10, 5), array(9, 6, 9, 8, 7, 8, 8, 10, 8, 5), array(8, 7, 7, 8, 7, 5, 6, 8, 9, 5), array(6, 5, 10, 5, 5, 10, 7, 8, 5, 5), array(10, 9, 8, 7, 6, 9, 7, 9, 6, 5)); // Calling function minTimeToExchange($k, $m, $n); // This code is contributed by anuj_67. ?>
Javascript
<script> // JavaScript code to find minimum // time to exchange notes // Function to calculate minimum // time to exchange note function minTimeToExchange(k, m, n) { let min = Number.MAX_VALUE; // Checking for every cashier for (let i = 0; i < n; i++) { // Time for changing the notes let temp = k[i] * 15; // Calculating scanning time // for every note for (let j = 0; j < k[i]; j++) { temp += m[i][j] * 5; } // If value in temp is minimum if (temp < min) min = temp; } document.write(min + "</br>"); } // number of cashiers let n = 5; // number of customers with // each cashier let k = [10, 10, 10, 10, 10]; // number of notes with each customer let 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); </script>
Producción:
480