Created
March 29, 2017 03:08
-
-
Save brun0xff/a758cf340ed659f266f2a5dfd90c7d9e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#define visitado 1 | |
#define nao_visitado 0 | |
#define INFINITO 1111111 | |
typedef struct elem{ | |
int pid; | |
int ing; | |
int dur; | |
int vis; | |
int ini; | |
int fim; | |
}tipoProc; | |
using namespace std; | |
int main() | |
{ | |
int n, t = 1; | |
while(cin >> n and n) | |
{ | |
tipoProc proc[n]; | |
for(int i=0; i<n; i++) | |
{ | |
proc[i].pid = i+1; | |
cin >> proc[i].ing; | |
cin >> proc[i].dur; | |
proc[i].vis = nao_visitado; | |
proc[i].ini = -1; | |
proc[i].fim = -1; | |
} | |
int cont = 0; | |
int ponto_reta = proc[0].ing; | |
tipoProc process[n]; | |
while(cont < n) | |
{ | |
int menor_id = 0; | |
int menor = INFINITO; | |
int i = 0; | |
while(proc[i].ing <= ponto_reta and i < n) | |
{ | |
if(proc[i].dur < menor and proc[i].vis == nao_visitado) | |
{ | |
menor_id = i; | |
menor = proc[i].dur; | |
} | |
i++; | |
} | |
proc[menor_id].vis = visitado; | |
process[cont] = proc[menor_id]; | |
ponto_reta = ponto_reta + proc[menor_id].dur; | |
cont++; | |
} | |
/* add em process tempo ini e fim */ | |
int dur_ant = 0; | |
for(int i=0; i<n; i++) | |
{ | |
process[i].fim = process[i].dur + dur_ant; | |
process[i].ini = process[i].fim - process[i].dur; | |
dur_ant = process[i].fim; | |
} | |
float tmex = 0, tmesp = 0; | |
for(int i=0; i<n; i++) | |
{ | |
tmex = tmex + (process[i].fim - process[i].ing); | |
tmesp = tmesp + (process[i].ini - process[i].ing); | |
} | |
cout << "Teste " << t << endl; | |
cout << "Tempo medio de execucao:" << tmex/n << "s" << endl; | |
cout << "Tempo medio de espera:" << tmesp/n << "s" << endl; | |
for(int i=0; i<n; i++) | |
{ | |
cout << "P" << process[i].pid << " "; | |
} | |
cout << endl; | |
cout << endl; | |
t++; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment