题目大意:给你一段内存,要你进行如下的三个操作。

1.分配内存  alloc   X ,分配连续一段长度为X的内存。
如果内存不够应该输出NULL,如果内存够就给这段内存标记一个编号。
2.擦除编号为 X的内存,erase X,  如果这段内存不存在那么输出“ILLEGAL_ERASE_ARGUMENT ”,否则什么都不输出。
3.整理内存,把所有的内存块整理到一块。
 
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
using namespace std;
typedef long long LL;
const int INF = 1e9+;
const int maxn = ; int Arr[maxn];
int n, m, a, ans;
int Blocks = ;
char op[]; int Alloc(int a)
{
for(int i=; i<=m; i++)
{
int j = i, num = ;
while(Arr[j] == && num != a && j <= m)
num ++, j ++;
if(num != a)
i = j;
else
{
Blocks ++;
for(int k=i; k<j; k++)
Arr[k] = Blocks;
return Blocks;
}
}
return ;
} int Erase(int Id)
{
if(Id <= )
return -;
bool flag = false;
for(int i=; i<=m; i++)
{
while(Arr[i] == Id)
Arr[i++] = , flag = true;
}
if(flag)
return -;
return -;
} int Defragment()
{
for(int i=; i<=m; i++)
{
if(Arr[i] == )
{
for(int j=i+; j<=m; j++)
{
if(Arr[j])
{
swap(Arr[i], Arr[j]);
break;
} }
}
}
return -;
} int main()
{ scanf("%d %d", &n, &m);
memset(Arr, , sizeof(Arr));
while(n --)
{
scanf("%s", op);
if(strcmp(op, "alloc") == )
{
scanf("%d", &a);
ans = Alloc(a);
}
else if( strcmp(op, "erase") == )
{
scanf("%d", &a);
ans = Erase(a);
}
else
ans = Defragment(); if( ans == )
puts("NULL");
else if(ans == -)
puts("ILLEGAL_ERASE_ARGUMENT");
else if(ans >= )
printf("%d\n", ans); } return ;
}

CodeForce 7 B - Memory Manager(模拟)的更多相关文章

  1. Codeforces Beta Round #7 B. Memory Manager 模拟题

    B. Memory Manager 题目连接: http://www.codeforces.com/contest/7/problem/B Description There is little ti ...

  2. Qualcomm device使用ION memory manager取代PMEM

    今天写好device,成功编译出CM,接下来肯定是调戏啦(你什么都没看到)~ BUG肯定也是一堆堆的!一开机,果然一堆error~可是尼玛,大蛋一放假就不见人了!!! 我自己折腾几个小时容易么我,我谷 ...

  3. Buffer Pool--SQL Server:Memory Manager 对象

    --=================================================================SELECT * FROM sys.sysperfinfoWHER ...

  4. Memory Manager surface area changes in SQL Server 2012

    here were various changes to memory related DMVs, DBCC memory status, and Perfmon counters in SQL Se ...

  5. Delphi 安装Cnpack cnvcl后界面不断弹出 Memory Manager's list capablity overflow ,please enlarge it!

    Delphi 安装Cnpack cnvcl后界面不断弹出 Memory Manager's list capablity overflow ,please enlarge it! 解决方法:删除指定  ...

  6. Codeforce 287A - IQ Test (模拟)

    In the city of Ultima Thule job applicants are often offered an IQ test. The test is as follows: the ...

  7. Understanding The Linux Virtual Memory Manager

    http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.588.4660&rep=rep1&type=pdf http://e ...

  8. lwIP Memory Management

    http://lwip.wikia.com/wiki/Lwipopts.h Memory management (RAM usage) /** * MEM_LIBC_MALLOC==1: Use ma ...

  9. Memory Management in Open Cascade

    Open Cascade中的内存管理 Memory Management in Open Cascade eryar@163.com 一.C++中的内存管理 Memory Management in ...

随机推荐

  1. android开发之AlertDialog点击按钮之后不消失 分类: android 学习笔记 2015-07-15 18:07 89人阅读 评论(0) 收藏

    最近有这样一个需求,我需要用户在一个弹出框里输入密码来验证,验证成功当然好说,但是如果验证失败则需要把alertdialog的标题改为"密码错误,请重新输入",并且这个alertd ...

  2. Configuring Robolectric

    There are numerous ways to customize how Robolectric behaves at runtime. Config Annotation The prima ...

  3. 使用PowerShell读、写、删除注册表键值

    访问注册表键值 在PowerShell中,用户可以通过类似于HKCU:(作为HKEY_CURRENT_USER)和HKLM:(代表HKEY_LOCAL_MATCHINE)的虚拟驱动器访问注册表键值. ...

  4. WisDom.Net 框架设计(三) 数据缓存

    WisDom.Net  --数据缓存 1.几种缓存方式       1.静态全局变量 C#静态变量使用 static 修饰符进行声明,在类被实例化时创建,通过类进行访问不带有 static 修饰符声明 ...

  5. ViewPager + Fragment 实现类微信界面

    在如今的互联网时代,微信已是一个超级App.这篇通过ViewPager + Fragment实现一个类似于微信的界面,之前有用FragmentTabHost实现过类似界面,ViewPager的实现方式 ...

  6. 阿里云服务器如何安装memcached

    方法/步骤 1 使用Xshell登陆阿里云服务器. 请使用root帐号登陆.下面的操作全部在home目录里执行 2 安装libevent. 输入命令 yum -y install libevent-d ...

  7. magic_quotes_gpc、mysql_real_escape_string、addslashes的区别及用法

    本篇文章,主要先重点说明magic_quotes_gpc.mysql_real_escape_string.addslashes 三个函数方法的含义.用法,并举例说明.然后阐述下三者间的区别.关系.一 ...

  8. C#操作求出SQL中某一字段所有行的和方法!

    DataTable table = xx.sqlcha(sql1);//调数据库 ; foreach(DataRow row in table.Rows)//遍历所查出记录所有行 { v = v + ...

  9. [转]Delphi调用cmd的两种方法

    delphi调用cmd的两种方法vars:string;begins:='cmd.exe /c '+edit1.Text+' >c:\1.txt';winexec(pchar(s),sw_hid ...

  10. nginx+php,502错误

    502错误基本就是php进程执行中挂了,其中有个原因就可能是进程执行超时设置导致的比如这个: ; The timeout for serving a single request after whic ...