比赛的时候队友要做这道题……
他没做出来自己也被误导了……
也算是个教训 自己还是要有自己的思路……
又是模拟题……
网上都是用vector做的 我最近才会stl 怎么会用那么高大上的的东西……
强力模拟一波内存……
反正只有100的大小 随意遍历……
模拟都做不出来 只能说明真的方了……
只要心态稳定 模拟都是水题……
1 #include<stdio.h> 2 #include<string.h> 3 int memory[102]; 4 int room[102]; 5 int main(){ 6 int T; 7 scanf("%d",&T); 8 while(T--){ 9 char s[10]; 10 int used=0; 11 int point=1; 12 while(~scanf("%s",s)&&strcmp(s,"End")!=0){ 13 if(strcmp(s,"Create")==0){ 14 int number; 15 scanf("%d",&number); 16 scanf("%d",&memory[number]); 17 int emp=0; 18 int ok=1; 19 for(int i=1;i<=100&&ok;i++){ 20 if(!room[i]) emp++; 21 if(emp>=memory[number]){ 22 int ii=i; 23 while(room[ii]==0){ 24 room[ii]=number; 25 ii--; 26 } 27 ok=0; 28 printf("Create process %d of size %d successfully! ",number,memory[number]); 29 } 30 else if(room[i+1]!=0&&ok) emp=0; 31 } 32 if(ok){ 33 memory[number]=0; 34 printf("No enough memory! "); 35 } 36 } 37 if(strcmp(s,"Delete")==0){ 38 int n; 39 scanf("%d",&n); 40 if(memory[n]==0) printf("No such process! "); 41 else{ 42 printf("Delete process %d of size %d successfully! ",n,memory[n]); 43 used-=memory[n]; 44 memory[n]=0; 45 for(int i=1;i<=100;i++) 46 if(room[i]==n) room[i]=0; 47 } 48 } 49 if(strcmp(s,"Print")==0){ 50 int emp=0; 51 int full=0; 52 for(int i=1;i<=100;i++){ 53 if(!room[i]) emp++; 54 else{ 55 if(emp){ 56 printf("H %d ",emp); 57 emp=0; 58 } 59 while(room[i++]&&room[i]==room[i-1]) full++; 60 printf("P %d %d ",room[--i],full+1); 61 full=0; 62 } 63 } 64 if(emp) printf("H %d ",emp); 65 } 66 } 67 memset(room,0,sizeof(room)); 68 memset(memory,0,sizeof(memory)); 69 } 70 return 0; 71 }