-
Notifications
You must be signed in to change notification settings - Fork 0
/
5 Camarero.cpp
48 lines (37 loc) · 1.19 KB
/
5 Camarero.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
// Estructura para almacenar información de cada cliente
struct Cliente {
int id;
int tiempoServicio;
};
// Comparador para ordenar los clientes por tiempo de servicio ascendente
bool comparador(const Cliente& a, const Cliente& b) {
return a.tiempoServicio < b.tiempoServicio;
}
// Función para maximizar las ganancias del camarero
double maximizarGanancias(vector<Cliente>& clientes) {
// Ordenar los clientes por tiempo de servicio ascendente
sort(clientes.begin(), clientes.end(), comparador);
double gananciaTotal = 0;
int tiempoAcumulado = 0;
// Calcular las ganancias basadas en el tiempo de espera de cada cliente
for (const Cliente& cliente : clientes) {
tiempoAcumulado += cliente.tiempoServicio;
gananciaTotal += 1.0 / tiempoAcumulado;
}
return gananciaTotal;
}
int main() {
vector<Cliente> clientes = {
{1, 5},
{2, 2},
{3, 3},
{4, 1}
};
double resultado = maximizarGanancias(clientes);
cout << "La ganancia máxima es: " << resultado << endl;
return 0;
}