Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. int allo[100][100],max[100][100],need[10][3],work[10],finish[10],temp1[10];
  6. int p,a,b,c,i,j,temp,w,k,track;
  7. int suma=0,sumb=0,sumc=0;
  8.  
  9. memset(finish,0,sizeof finish);
  10.  
  11. cout<<"enter the no of process"<<endl;
  12. cin>>p;
  13. //cout<<"enter the resources"<<endl;
  14. //cin>>a>>b>>c;
  15.  
  16. cout<<"enter the available"<<endl;
  17. for(i=0; i<3; i++)
  18. {
  19. cin>>work[i];
  20. }
  21. cout<<"enter the allocation"<<endl;
  22. for(i=0; i<p; i++)
  23. {
  24. for(j=0; j<3; j++)
  25. {
  26. cin>>allo[i][j];
  27. }
  28. }
  29. cout<<"enter the max"<<endl;
  30. for(i=0; i<p; i++)
  31. {
  32. for(j=0; j<3; j++)
  33. {
  34. cin>>max[i][j];
  35. }
  36. }
  37.  
  38. for(i=0; i<p; i++)
  39. {
  40. for(j=0; j<3; j++)
  41. {
  42. need[i][j]=(max[i][j]-allo[i][j]);
  43.  
  44. }
  45. }
  46.  
  47.  
  48. while(1){
  49. for(i=0; i<p; i++)
  50. {
  51. track=0;
  52. for(j=0; j<3; j++)
  53. {
  54. if(need[i][j]<=work[j])
  55. {
  56. track++;
  57. }
  58.  
  59. }
  60. if(track==3)
  61. {
  62. for(j=0; j<3; j++)
  63. {
  64.  
  65. work[j]=work[j]+allo[i][j];
  66.  
  67. }
  68. finish[i]=1;
  69. cout<<i<<endl;
  70.  
  71. }
  72.  
  73. }
  74. int ck=1;
  75. for(i=0; i<p; i++){
  76. if(finish[i]==0)
  77. ck=0;
  78. }
  79. if(ck==1)
  80. break;
  81.  
  82. }
  83.  
  84.  
  85.  
  86. /*
  87. for(i=0; i<p; i++)
  88. {
  89. if(finish[i]==0&&need[i][j]<=work[j])
  90. {
  91. work[j]=work[j]+allo[i][j];
  92.  
  93. }
  94.  
  95.  
  96. }
  97.  
  98.  
  99.  
  100.  
  101.  
  102. for(i=0; i<p; i++)
  103. {
  104. for(j=0; j<3; j++)
  105. {
  106. cout<<need[i][j];
  107. }
  108. cout<<endl;
  109.  
  110. }*/
  111.  
  112.  
  113.  
  114. }
  115.  
  116. /*
  117.  
  118. 0 1 0
  119. 2 0 0
  120. 3 0 2
  121. 2 1 1
  122. 0 0 2
  123.  
  124.  
  125.  
  126.  
  127. 7 5 3
  128. 3 2 2
  129. 9 0 2
  130. 2 2 2
  131. 4 3 3
  132.  
  133. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement