Advertisement
Guest User

Untitled

a guest
Jan 25th, 2020
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4.  
  5. /*
  6. 5
  7. 1 1 5
  8. 2 3 6
  9. 3 10 1
  10. 4 15 1
  11. 5 16 2
  12. */
  13.  
  14.  
  15. int main()
  16. {
  17. ll p;
  18. cout<<"Enter how many process are there:";
  19. cin>>p;
  20. cout<<endl;
  21. ll ar[p][3];
  22. for(ll i=0;i<p;i++){
  23. for(ll j=0;j<3;j++){
  24. cin>>ar[i][j];
  25. }
  26. }
  27. vector<pair<ll,ll> > vp;
  28. vp.push_back(make_pair(ar[0][1],ar[0][1]+ar[0][2]));
  29. ll prev=ar[0][1]+ar[0][2];
  30. for(ll i=1;i<p;i++){
  31. if(prev>=ar[i][1]){
  32. vp.push_back(make_pair(prev,prev+ar[i][2]));
  33. prev=prev+ar[i][2];
  34. }
  35. else{
  36. vp.push_back(make_pair(ar[i][1],ar[i][1]+ar[i][2]));
  37. prev=ar[i][1]+ar[i][2];
  38. }
  39. }
  40. cout<<"1 process start at "<<vp[0].first<<" and ends at "<<vp[0].second<<endl;
  41. for(ll i=1;i<vp.size();i++){
  42. if(vp[i].first==vp[i-1].second){
  43. cout<<i+1<<" process start at "<<vp[0].first<<" and ends at "<<vp[0].second<<endl;
  44. }
  45. else{
  46. cout<<"from "<<vp[i-1].second<<" to "<<vp[i].first<<"is idle time"<<endl;
  47. cout<<i+1<<" process start at "<<vp[0].first<<" and ends at "<<vp[0].second<<endl;
  48. }
  49. }
  50. ll table[p][6];
  51. for(ll i=0;i<p;i++){
  52. table[i][0]=i+1;
  53. table[i][1]=ar[i][1];
  54. table[i][2]=vp[i].first;
  55. table[i][3]=vp[i].second;
  56. table[i][4]=abs(table[i][1]-table[i][2]);
  57. table[i][5]=abs(table[i][3]-table[i][1]);
  58. }
  59. double awt =0, atat=0;
  60. for(ll i=0;i<p;i++){
  61. awt+=table[i][4];
  62. atat+=table[i][5];
  63. for(ll j=0;j<6;j++) cout<<table[i][j]<<" ";
  64. cout<<endl;
  65. }
  66. cout<<"the average waiting time is ="<<awt/p<<endl;
  67. cout<<"the average turn around time is ="<<atat/p<<endl;
  68. return 0;
  69.  
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement