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 ...
随机推荐
- Android 中 SQLite 性能优化
数据库是应用开发中常用的技术,在Android应用中也不例外.Android默认使用了SQLite数据库,在应用程序开发中,我们使用最多的无外乎增删改查.纵使操作简单,也有可能出现查找数据缓慢,插入数 ...
- iOS 数据持久化(1):属性列表与对象归档
@import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css); @import url(/ ...
- ArcEngine:栅格分级渲染
ArcEngine对矢量数据进行风格化实在是得心应手,同样的对于栅格图像也能进行风格化!以前没接触过,今天正好需要,做出了栅格图像的渲染!下面实现的思路: 1.定义渲染的一系列接口 2.判断图像是否建 ...
- codevs 1817 灾后重建
/* 暴力暴力 离线每次添边 堆优化dij 70 SPFA 80..... */ #include<iostream> #include<cstdio> #include< ...
- 9.21 noip模拟试题
Problem 1 护花(flower.cpp/c/pas) [题目描述] 约翰留下他的N(N<=100000)只奶牛上山采木.他离开的时候,她们像往常一样悠闲地在草场里吃草.可是,当他回来的时 ...
- Unity3D GUI学习
Unity3D内置有GUI, 首先,使用GUI实现一个按钮,并且点击实现触发, void OnGUI() { //GUI.Button (new Rect (10,10,50,50), "n ...
- C## 输出Hello world
首先新建一个项目 然后在文件D:\C##Obj\HelloWorld\HelloWorld\Program.cs using System; using System.Collections.Gene ...
- VS2015 Cordova Ionic移动开发(五)
一.创建侧边菜单和导航项目 1.使用VS创建一个Ionic空项目,同时创建一个Ionic SideMenu和Ionic Tabs项目.将SideMenu和Tabs项目里的templates和js文件合 ...
- C#-日期格式表
自定义格式表: 格式模式 说明 d 月中的某一天.一位数的日期没有前导零. dd 月中的某一天.一位数的日期有一个前导零. ...
- ToString格式.
C 货币 2.5.ToString("C") ¥2.50 D 十进制数 25.ToString("D5") 00025 E 科学型 25000.ToString ...