CodeForce 7 B - Memory Manager(模拟)
题目大意:给你一段内存,要你进行如下的三个操作。
#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(模拟)的更多相关文章
- Codeforces Beta Round #7 B. Memory Manager 模拟题
B. Memory Manager 题目连接: http://www.codeforces.com/contest/7/problem/B Description There is little ti ...
- Qualcomm device使用ION memory manager取代PMEM
今天写好device,成功编译出CM,接下来肯定是调戏啦(你什么都没看到)~ BUG肯定也是一堆堆的!一开机,果然一堆error~可是尼玛,大蛋一放假就不见人了!!! 我自己折腾几个小时容易么我,我谷 ...
- Buffer Pool--SQL Server:Memory Manager 对象
--=================================================================SELECT * FROM sys.sysperfinfoWHER ...
- 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 ...
- Delphi 安装Cnpack cnvcl后界面不断弹出 Memory Manager's list capablity overflow ,please enlarge it!
Delphi 安装Cnpack cnvcl后界面不断弹出 Memory Manager's list capablity overflow ,please enlarge it! 解决方法:删除指定 ...
- Codeforce 287A - IQ Test (模拟)
In the city of Ultima Thule job applicants are often offered an IQ test. The test is as follows: the ...
- 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 ...
- lwIP Memory Management
http://lwip.wikia.com/wiki/Lwipopts.h Memory management (RAM usage) /** * MEM_LIBC_MALLOC==1: Use ma ...
- Memory Management in Open Cascade
Open Cascade中的内存管理 Memory Management in Open Cascade eryar@163.com 一.C++中的内存管理 Memory Management in ...
随机推荐
- java解析xml文件四种方式
1.介绍 1)DOM(JAXP Crimson解析器) DOM是用与平台和语言无关的方式表示XML文档的官方W3C标准.DOM是以层次结构组织的节点或信息片断的集合.这个层次结构允许开发人员在树中寻找 ...
- java文件处理工具类
import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.BufferedRead ...
- 调试exynos4412—ARM嵌入式Linux—LEDS/GPIO驱动之一
/** ****************************************************************************** * @author 暴走的小 ...
- Python之路【第十一篇】:CSS --暂无内容-待更新
Python之路[第十一篇]:CSS --暂无内容-待更新
- 详细查看数据库SQL执行计划
DBCC DROPCLEANBUFFERS 清除数据缓存DBCC FREEPROCCACHE 清除执行计划缓存 SET SHOWPLAN_XML ON 此语句导致 SQL Server 不执行 Tr ...
- git 教程 git.oschina.net
官方说明:http://git.oschina.net/oschina/git-osc/wikis/%E5%B8%AE%E5%8A%A9#ssh-keys 安装完成后,在开始菜单里找到"Gi ...
- 显示scrollbar
修改CSS overflow的值 overflow: 参考MDN 例子: overflow: auto or scroll
- Linux通配符
* 任意字符 ?任意单个字符 [] 匹配指定 字符范围内的字符 [^] 指定范围之外的单个字符 常规字符集合 [a-z] a到z的所有小写字母 [A-Z] a到z的所有大写字母 [0-9] 0到9的所 ...
- 通过移位与或非运算获取整形最大值,最小值,以及获取输入的int类型整数的二进制表示
以上是最终效果 实现类: package com.corejava.chap02; public class IntBin { private int value; public IntBin(int ...
- 【POJ1151】【扫描线+线段树】Atlantis
Description There are several ancient Greek texts that contain descriptions of the fabled island Atl ...