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

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. Servlet创建、编译、部署、运行

    最近在做一个通过Servlet实现后台批量接收上传文件的东西,现将Servlet的开发.运行配置.调用记录下来.我们以最简单的FileUpload为例,目前所有的http协议相关的Servlet均继承 ...

  2. 设置div中文字超出时自动换行

    一.对于div强制换行1.(IE浏览器)white-space:normal; word-break:break-all;这里前者是遵循标准.#wrap{white-space:normal; wid ...

  3. asp.net mvc 实现记忆返回的功能

    大体思路是在当前跳转链接追加一个参数memoryguid,以guid为key把查询query保存在cookie里,跳转的时候带走这个guid,回来的时候还带着,这样我们就能根据这个guid从cooki ...

  4. 基于事件的异步模式——BackgroundWorker

    实现异步处理的方法很多,经常用的有基于委托的方式,今天记录的是基于事件的异步模式.利用BackgroundWorker组件可以很轻松的实现异步处理,并且该组件还支持事件的取消.进度报告等功能.本文以计 ...

  5. LayoutInflater类详解

    http://www.cnblogs.com/top5/archive/2012/05/04/2482328.html   在实际开发中LayoutInflater这个类还是非常有用的,它的作用类似于 ...

  6. 关于ASP.NET控件方面的学习(恢复版)

    前段时间没有把学习中的遇到的问题和解决方法详细总结,今天整理整理.. 鉴于我们这个研究生论文管理系统是小组形式,所以说虽然我只负责数据库,但是其它部分也多少有些工作方面的涉及,最后感谢各位同学和老师的 ...

  7. CSRF 攻击的应对之道

    转载自imb文库 CSRF(Cross Site Request Forgery, 跨站域请求伪造)是一种网络的攻击方式,该攻击可以在受害者毫不知情的情况下以受害者名义伪造请求发送给受攻击站点,从而在 ...

  8. iOS GCD多线程介绍

    GCD:是纯C语言写的,是苹果公司为多核的并行运算提出的解决方案. GCD的两个核心概念: - 任务 - 队列 将任务添加到队列中 GCD会自动将队列中的任务取出,放到对应的线程中执行 任务的取出遵循 ...

  9. IIS7.5 去除 index.php web.config配置文件

    论坛里有很多关于去掉index.php的教程和代码,但是悲剧的是都是自己能配置服务器,并且服务器要么是 Apache,就是IIS 6- ...没有IIS7.5下是如何配置的. 我想大家应该有很多都是用 ...

  10. js手机站跳转

    var yunzhuanhua_pc_domain = "http://www.域名.com#yht"; //PC站网址var yunzhuanhua_wap_domain = & ...