Skip to content

Instantly share code, notes, and snippets.

@Biazus
Last active February 14, 2023 17:12
Show Gist options
  • Save Biazus/c3ab21f52a07d82488bf to your computer and use it in GitHub Desktop.
Save Biazus/c3ab21f52a07d82488bf to your computer and use it in GitHub Desktop.
Desafios : Aula 2, Atividade 3 - The Lonesome Cargo Distributor
#include <iostream>
#include <stack>
#include <queue>
using namespace std;
int main() {
int SET = 0;
cin >> SET;
while(SET){
// S a capacidade de carga do carregador
// Q o tamanho da estacao
int i, j, N, S, Q, destination = 0, currentStation = 0;
int numberOfMinutes=0;
stack<int> carrier;
queue<int> stationBQueue[100];
cin >> N >> S >> Q;
for(i=0;i < N; i++){
int numberOfCargoes;
cin >> numberOfCargoes;
for(j=0; j < numberOfCargoes; j++){
cin >> destination;
stationBQueue[i].push(destination - 1); //porque começa em 0
}
}
while(1){ //descarregar a carga na estacao
while(!carrier.empty() && (carrier.top() == currentStation || stationBQueue[currentStation].size() < Q)){
if (carrier.top() != currentStation) {
stationBQueue[currentStation].push(carrier.top());
}
carrier.pop();
numberOfMinutes += 1;//fazer uma descarga leva 1min
}
while(carrier.size() < S && !stationBQueue[currentStation].empty()){
carrier.push(stationBQueue[currentStation].front());
stationBQueue[currentStation].pop();
numberOfMinutes += 1;//fazer uma carga leva 1min
}
int k, finished=0;
for (k=0; k < N; k++){
if (stationBQueue[k].empty()) finished++;
}
if(finished==N && carrier.empty()) break;
currentStation = (currentStation + 1) % N;
numberOfMinutes += 2; //mudar estacao leva 2min
}
cout << numberOfMinutes << endl;
SET--;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment