气死我了...这个毒瘤内存分配.....

优先队列 + 链表模拟,看起来搞一搞就好了却WA来WA去...

最后对拍手动找才发现错误:

erase的时候不要急急忙忙插入wait!要把同一时期的erase完再插入wait!

 #include <cstdio>
#include <queue>
typedef long long LL;
const LL N = ;
const LL INF = 1ll << ; struct Ask {
LL time, len, last;
Ask(LL t, LL l, LL s) {
time = t;
len = l;
last = s;
}
}; struct Out {
LL time, pos;
Out(LL t, LL p) {
time = t;
pos = p;
}
inline bool operator <(const Out &x) const {
return time > x.time;
}
}; struct ListNode {
LL pre, nex, l, r;
bool vis;
}li[N]; LL head = N - , tail = N - , top = ; LL n;
std::queue<Ask> Wait, Come;
std::priority_queue<Out> Erase; inline void init() {
li[head].nex = ;
li[].pre = head;
li[].nex = tail;
li[].l = ;
li[].r = n - ;
li[tail].pre = ;
return;
} inline LL getpos(LL k) {
LL p = li[head].nex;
while(p != tail) {
while(li[p].vis) {
p = li[p].nex;
}
if(p == tail) {
return ;
}
if(li[p].r - li[p].l + >= k) {
return p;
}
p = li[p].nex;
}
return ;
} inline LL insert(Ask x) {
LL p = getpos(x.len);
if(!p) {
return ;
}
if(li[p].r - li[p].l + == x.len) {
li[p].vis = ;
return p;
}
++top;
li[top].r = li[p].r;
li[top].l = li[p].l + x.len;
li[p].r = li[top].l - ;
li[p].vis = ;
li[top].nex = li[p].nex;
li[top].pre = p;
li[p].nex = top;
li[li[top].nex].pre = top;
return p;
} inline void erase(Out x) {
LL p = x.pos;
li[p].vis = ; /// b p c
LL b = li[p].pre, c = li[p].nex;
if((li[b].vis || b == head) && (li[c].vis || c == tail)) {
return;
}
if(li[b].vis || b == head) {
li[p].nex = li[c].nex;
li[li[c].nex].pre = p;
li[p].r = li[c].r;
return;
}
if(li[c].vis || c == tail) {
li[p].pre = li[b].pre;
li[li[b].pre].nex = p;
li[p].l = li[b].l;
return;
}
li[p].nex = li[c].nex;
li[p].pre = li[b].pre;
li[li[c].nex].pre = p;
li[li[b].pre].nex = p;
li[p].l = li[b].l;
li[p].r = li[c].r;
return;
} int main() {
LL t, len, last;
int c = , w = ;
scanf("%lld", &n);
init();
while() {
scanf("%lld%lld%lld", &t, &len, &last);
if(!t && !len && !last) {
break;
}
Come.push(Ask(t, len, last));
}
LL sum = , T = ;
while(!Wait.empty() || !Come.empty() || !Erase.empty()) {
LL tc = INF, te = INF;
if(!Come.empty()) {
tc = Come.front().time;
}
if(!Erase.empty()) {
te = Erase.top().time;
}
if(te <= tc) {
while(Erase.top().time == te) {
erase(Erase.top());
Erase.pop();
if(Erase.empty()) {
break;
}
}
T = te;
LL in = ;
while(!Wait.empty()) {
in = insert(Wait.front());
if(!in) {
break;
}
Erase.push(Out(te + Wait.front().last, in));
Wait.pop();
}
}
else {
LL in = insert(Come.front());
if(in) {
Erase.push(Out(tc + Come.front().last, in));
}
else {
Wait.push(Come.front());
sum++;
}
Come.pop();
}
} printf("%lld\n%lld", T, sum);
return ;
}

AC代码

poj1193 内存分配的更多相关文章

  1. 《深入理解Java虚拟机》内存分配策略

    上节学习回顾 1.判断对象存活算法:引用计数法和可行性分析算法 2.垃圾收集算法:标记-清除算法.复制算法.标记-整理算法 3.垃圾收集器: Serial:新生代收集器,采用复制算法,单线程. Par ...

  2. Java的内存分配

    java内存分配 A:栈 存储局部变量 B:堆 存储所有new出来的 C:方法区(方法区的内存中) 类加载时 方法信息保存在一块称为方法区的内存中, 并不随你创建对象而随对象保存于堆中; D:本地方法 ...

  3. C语言内存分配方法。

    当C程序运行在操作系统上时,操作系统会给每一个程序分配一定的栈空间. 堆为所有程序共有的,需要时需要申请访问. 一.栈 局部变量.函数一般在栈空间中. 运行时自动分配&自动回收:栈是自动管理的 ...

  4. JVM内存分配策略

    在 JVM内存垃圾回收方法 中,我们已经详细讨论了内存回收,但是,我们程序中生成的对象是如何进行分配的呢?以下所述针对的是HotSpot虚拟机. 1.Java堆结构 以HotSpot为例,如下图: H ...

  5. Java的垃圾回收和内存分配策略

    本文是<深入理解Java虚拟机 JVM高级特性与最佳实践>的读书笔记 在介绍Java的垃圾回收方法之前,我们先来了解一下Java虚拟机在执行Java程序的过程中把它管理的内存划分为若干个不 ...

  6. Buddy内存分配算法

    Buddy(伙伴的定义): 这里给出伙伴的概念,满足以下三个条件的称为伙伴:1)两个块大小相同:2)两个块地址连续:3)两个块必须是同一个大块中分离出来的: Buddy算法的优缺点: 1)尽管伙伴内存 ...

  7. 小白请教几个关于Java虚拟机内存分配策略的问题

    最近在看周志明所著的<深入理解Java虚拟机>,有几个问题不太明白,希望对虚拟机有研究的哥们儿帮我解答一下.先说一下我进行试验的环境: 操作系统:Mac OS X 10.11.6 EI C ...

  8. Linux内核笔记--内存管理之用户态进程内存分配

    内核版本:linux-2.6.11 Linux在加载一个可执行程序的时候做了种种复杂的工作,内存分配是其中非常重要的一环,作为一个linux程序员必然会想要知道这个过程到底是怎么样的,内核源码会告诉你 ...

  9. Linux内核笔记——内存管理之块内存分配

    内核版本:linux-2.6.11 伙伴系统 伙伴系统是linux用于满足对不同大小块物理内存分配和释放请求的解决方案. 内存管理区 linux将物理内存分成三个内存管理区,分别为ZONE_DMA Z ...

随机推荐

  1. day 7-8 协程

    不能无限的开进程,不能无限的开线程最常用的就是开进程池,开线程池.其中回调函数非常重要回调函数其实可以作为一种编程思想,谁好了谁就去调 只要你用并发,就会有锁的问题,但是你不能一直去自己加锁吧那么我们 ...

  2. logback框架之——日志分割所带来的潜在问题

    源码: logback-test.xml文件如下,有2个需要我们重点关注的参数: fileNamePattern:这里的日志文件名变动的部分是年月日时,外加1个文件分割自增变量,警告,年月日时的数值依 ...

  3. mongodb的安装方法

    下载安装 mongodb官网下载地址:https://www.mongodb.org/downloads#produc...直接下载.msi文件并安装到指定目录即可.我的安装路径是D:\mongodb ...

  4. CART算法与剪枝原理

    参考:https://blog.csdn.net/u014688145/article/details/53326910 知乎:https://www.zhihu.com/question/22697 ...

  5. Entity Framework 6 自定义连接字符串ConnectionString连接MySQL

    在开始介绍之前,首先来看看官方对Entity Framework的解释:Entity Framework (EF) is an object-relational mapper that enable ...

  6. BugFree 安装

    BugFree基于PHP和MySQL开发,是免费且开发源代码的缺陷管理系统.服务器端在Linux和Windows平台上都可以运行:客户端无需安装任何软件,通过IE,FireFox等浏览器就可以自由使用 ...

  7. 一、Dev

    一.获取选中的表格 // MessageBox.Show(gridview_Parent.GetFocusedDataRow()["series"].ToString());//获 ...

  8. WGS84,GCJ02, BD09坐标转换

    public class Gps { private double wgLat; private double wgLon; public Gps(double wgLat, double wgLon ...

  9. Web API 2 Entity Framework 使用 Procedure

    Recently I worked on a project, which I started as code first and then I forced to switch to Databas ...

  10. SharePoint 2013 使用 RBS 功能将二进制大型对象 BLOB 存储在内容数据库外部。

    为每个内容数据库设置 BLOB 存储   启用并配置 FILESTREAM 之后,请按照以下过程在文件系统中设置 BLOB 存储.必须为要对其使用 RBS 的每个内容数据库设置 BLOB 存储. 设置 ...