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

优先队列 + 链表模拟,看起来搞一搞就好了却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. 字符串正则替换replace第二个参数是函数

    zepto中 //将字符串转成驼峰式的格式 camelize = function (str) { return str.replace(/-+(.)?/g, function (match, chr ...

  2. 关于golang.org/x包问题

    关于golang.org/x包问题 由于谷歌被墙,跟谷歌相关的模块无法通过go get来下载,解决方法: git clone https://github.com/golang/net.git $GO ...

  3. java学习之—数组的曾删改查

    /** * 数组的曾删改查 * Create by Administrator * 2018/6/8 0008 * 上午 9:54 **/ public class HighArray { priva ...

  4. ArcGIS 添加 MarkerSymbol 弹出“图形符号无法序列化为 JSON”错误

    今天在做一个demo,向自定义图层中添加MarkerSymbol的时候,弹出“图形符号无法序列化为 JSON”错误,之前都没有出现过这个问题,我们首先来看一看我是怎样去添加图层,然后向图层中添加Gra ...

  5. Spring Aop实例@Aspect、@Before、@AfterReturning@Around 注解方式配置

    用过spring框架进行开发的人,多多少少会使用过它的AOP功能,都知道有@Before.@Around和@After等advice.最近,为了实现项目中的输出日志和权限控制这两个需求,我也使用到了A ...

  6. Nginx 缓存针对打开的文件句柄与原文件信息

    L:108 open_file_cache syntax: open_file_cache off;   open_file_cache max=N[inactive=time](inactive表示 ...

  7. Siki的虚幻第一季

    空项目.一闪而过的解决方法 命名空间std::cout的作用: int ,long , long long类型的范围 unsigned   int   0-4294967295 int   21474 ...

  8. Gedit浏览器常用快捷键备注

    此处只记录常用的,而通常意义上的应知应会不做汇总 搜索 : Ctrl +F : 查找字符串 Ctrl + G : 查找字符串的下一实例 Ctrl + Shift + G : 查找字符串的前一实例 Ct ...

  9. chrome实用快捷键速记

    标签页和窗口快捷键 操作 快捷键 打开新窗口 Ctrl + n 无痕模式下打开新窗口 Ctrl + Shift + n 打开新的标签页,并跳转到该标签页 Ctrl + t 重新打开最后关闭的标签页,并 ...

  10. jsp页面中 <%%> <%! %>, <%=%> <%-- --%>有什么区别

    <%%> 可添加java代码片段   <%! %>       可添加java方法   <%=%>       变量或表达式值输出到页面 <%-- --%&g ...