Created
March 29, 2017 03:08
-
-
Save brun0xff/3303ffd99729c6c5b2e5b181fa63d5d6 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> | |
using namespace std; | |
int main() | |
{ | |
int n, t=1; | |
while(cin >> n and n) | |
{ | |
int m[n][4], fim_ant = -1; | |
for(int i=0; i<n; i++) | |
{ | |
/* m[0][i] = ingresso */ | |
/* m[2][i] = duracao */ | |
cin >> m[i][0] >> m[i][2]; | |
} | |
/* monta matriz com todas informações úteis */ | |
/* ingresso | inicio | duracao | fim */ | |
/* numeros de linhas == numero de processos */ | |
for(int i=0; i<n; i++) | |
{ | |
if(m[i][0] < fim_ant) | |
{ | |
m[i][1] = fim_ant; | |
} | |
else | |
{ | |
m[i][1] = m[i][0]; | |
} | |
m[i][3] = m[i][1] + m[i][2]; | |
fim_ant = m[i][3]; | |
} | |
/* tempo medio de execucao */ | |
/* tempo medio de espera */ | |
float tmexe = 0, tmesp = 0; | |
for(int i=0; i<n; i++) | |
{ | |
tmexe = tmexe + (m[i][3]-m[i][0]); | |
tmesp = tmesp + (m[i][1]-m[i][0]); | |
} | |
cout << "Teste " << t << endl; | |
cout << "Tempo medio de execucao:" << tmexe/n << "s" << endl; | |
cout << "Tempo medio de espera:" << tmesp/n << "s" << endl; | |
/* esse algoritmo executa sempre na ordem de chegada */ | |
for(int i=1; i<=n; i++) | |
{ | |
cout << "P" << i << " "; | |
} | |
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