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 ...
随机推荐
- Thread Runnable 多线程
1. 实现多线程的两种方法 a) 让这个类继承java.lang.Thread,然后重写run方法 b) 让这个类实现 java.lang.Runnable接口,实现r ...
- partial局部类
局部类型允许我们将一个类.接口或结构分成好几个部分,分别实现在几个不同的.cs文件中. 局部类型适用于以下情况: (1)类型特别大,不宜放在一个文件中实现. (2)一个类型中的一部分代码为自动化工具生 ...
- sql知识点的积累和使用过的例子
越来越发现自己的sql方面的知识的欠缺,所以只能放低姿态一点一点的学了 一 游标和charIndex的使用. 游标我一直没用过,以前只是在同事们写的存储过程里见过,但是一直没看明白(可是我就是比较笨吧 ...
- JavaScript Math对象
Math对象是JavaScript的一个固有对象,其作用是执行常见的算数任务.该对象的使用并不是像Date,Array对象使用 new关键字来得到对象,而是直接 Math.[{property|met ...
- List指定字段赋特定值(非循环) asp.net
List<Cart> cartd=cartd.Where(p => (p.Id= "123").Length > -1).ToList(); 把Id的值都赋 ...
- 实现多个ContentProvider对多张表进行操作
http://blog.csdn.net/maylian7700/article/details/7365373 SQLite数据库直接操作类: DatabaseHelper.java package ...
- base64加密解密文件
1 //字符串加密 -(void)demo1 { //普通的 8 bit二进制数据 NSString *str = @"hello world!"; //将字符串转换成二进制数据 ...
- 基于ProGuard-Maven-Plugin的自定义代码混淆插件
介绍 大家可能都会碰到一些代码比较敏感的项目场景,这个时候代码被反编译看到就不好了,这个时候就需要代码混淆插件来对代码进行混淆了. 基于Maven的项目一般会去考虑使用proguard-maven-p ...
- IOI1994 北京2008的挂钟 迭代加深
总的来讲,这是一道很⑨的题,因为: (1)题目中有⑨个挂钟 (2)有⑨种操作方案 (3)这题因为解空间太小所以可以直接⑨重循环!! 这题可以用迭代加深搜索高效求解,剪枝的策略也很显然: >所求的 ...
- C++最后课程项目总结
第一次独立完成的C++小项目,40小时 + 5小时Update + 8小时Linux移植. 过程: 过程非常认真,一个星期主要就是忙这个,为了完成某个部分,有时饭都推迟吃,连续对着电脑10几个小时很累 ...