Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int main()
- {
- int allo[100][100],max[100][100],need[10][3],work[10],finish[10],temp1[10];
- int p,a,b,c,i,j,temp,w,k,track;
- int suma=0,sumb=0,sumc=0;
- memset(finish,0,sizeof finish);
- cout<<"enter the no of process"<<endl;
- cin>>p;
- //cout<<"enter the resources"<<endl;
- //cin>>a>>b>>c;
- cout<<"enter the available"<<endl;
- for(i=0; i<3; i++)
- {
- cin>>work[i];
- }
- cout<<"enter the allocation"<<endl;
- for(i=0; i<p; i++)
- {
- for(j=0; j<3; j++)
- {
- cin>>allo[i][j];
- }
- }
- cout<<"enter the max"<<endl;
- for(i=0; i<p; i++)
- {
- for(j=0; j<3; j++)
- {
- cin>>max[i][j];
- }
- }
- for(i=0; i<p; i++)
- {
- for(j=0; j<3; j++)
- {
- need[i][j]=(max[i][j]-allo[i][j]);
- }
- }
- while(1){
- for(i=0; i<p; i++)
- {
- track=0;
- for(j=0; j<3; j++)
- {
- if(need[i][j]<=work[j])
- {
- track++;
- }
- }
- if(track==3)
- {
- for(j=0; j<3; j++)
- {
- work[j]=work[j]+allo[i][j];
- }
- finish[i]=1;
- cout<<i<<endl;
- }
- }
- int ck=1;
- for(i=0; i<p; i++){
- if(finish[i]==0)
- ck=0;
- }
- if(ck==1)
- break;
- }
- /*
- for(i=0; i<p; i++)
- {
- if(finish[i]==0&&need[i][j]<=work[j])
- {
- work[j]=work[j]+allo[i][j];
- }
- }
- for(i=0; i<p; i++)
- {
- for(j=0; j<3; j++)
- {
- cout<<need[i][j];
- }
- cout<<endl;
- }*/
- }
- /*
- 0 1 0
- 2 0 0
- 3 0 2
- 2 1 1
- 0 0 2
- 7 5 3
- 3 2 2
- 9 0 2
- 2 2 2
- 4 3 3
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement