codeforces 7B - Memory Manager
来源:互联网 发布:淘宝手机店招图片素材 编辑:程序博客网 时间:2024/06/03 22:34
模拟操作系统的内存分配原理
#include<stdio.h>
#include<stdlib.h>#include<string.h>
#define M 100+5
int mem[M]; char s[15];
int t,m;
int check(int x,int c){
int i,j,f;
for(i=1;i<=m-x+1;i++){
f=0;
for(j=i;j<i+x;j++)
if(mem[j]!=0)f=1;
if(f==0){
for(j=i;j<i+x;j++)
mem[j]=c;
return 1;
}
}
return 0;
}
int main(){
int i,j,c,x,f;
while(~scanf("%d %d",&t,&m)){
c=1;
memset(mem,0,sizeof(mem));
while(t--){
scanf("%s",s);
if(s[0]=='a'){
scanf("%d",&x);
if(check(x,c)==1)printf("%d\n",c++);
else puts("NULL");
}else if(s[0]=='e'){
scanf("%d",&x);
if(x==0)puts("ILLEGAL_ERASE_ARGUMENT");
else{
f=0;
for(i=1;i<=m;i++)
if(mem[i]==x){
mem[i]=0;
f=1;
}
if(f==0)puts("ILLEGAL_ERASE_ARGUMENT");
}
}else if(s[0]=='d'){
i=j=1;
while(j<=m){
mem[i]=mem[j];
if(mem[i]!=0){
if(j>i)mem[j]=0;
i++;
}
j++;
}
}
}
}
return 0;
}
- codeforces 7B - Memory Manager
- CodeForces 7B Memory Manager 模拟题
- CodeForces 7B Memory Manager(中等难度模拟题)
- codeforce 7B. Memory Manager
- #7 B. Memory Manager(细节+模拟)
- B - Memory Manager
- B - Memory Manager
- codeforces B. Memory and Trident
- CodeForces 712B Memory and Trident
- codeforces 712B Memory and Trident
- Codeforces-712B-Memory and Trident
- Codeforces Problem 712B Memory and Trident(implementation)
- Codeforces #370 (Div.2) B. Memory and Trident【思维】
- Codeforces #370 (Div.2) B. Memory and Trident【思维】
- Codeforces 712B Memory and Trident 简单贪心
- CodeForces-712B. Memory and Trident(模拟)
- Ojb-C memory manager
- task manager memory meaning
- linux乱码问题:LANG变量的秘诀
- String path = request.getContextPath路径问题
- 最火的Android开源项目(4
- C#中类、抽象类、接口的比较
- CentOS 6.3/6.4 Minimal 源码安装 MySQL 5.6.10/5.6.11
- codeforces 7B - Memory Manager
- InstaSearch - Eclipse plug-in for quick code search
- SVN Checkout 工程时未弹出要输入用户名密码,但被forbidden的情况
- 黑马程序员——多线程
- struts2中action接收参数的方法
- java读取TXT文件的方法
- Android开发(8)--Android中DOM解析xml文件
- 最火的Android开源项目(5
- 计算字符串的相似度--编程之美3.3