比赛 |
20250904开学热身赛 |
评测结果 |
EEEEE |
题目名称 |
内存分配 |
最终得分 |
0 |
用户昵称 |
ChenBp |
运行时间 |
0.730 s |
代码语言 |
C++ |
内存使用 |
3.38 MiB |
提交时间 |
2025-09-04 21:57:59 |
显示代码纯文本
#include <iostream>
#include <queue>
using namespace std;
struct listnode {
int ms, md;
listnode *next, *from;
};
listnode *head = NULL;
struct wai {
int m, p, t;
};
queue<wai> waiting;
struct usep {
int ms, md, t;
bool operator<(const usep &y) const { return t < y.t; }
};
priority_queue<usep> use;
void add(int ms, int md, listnode *from, listnode *next) {
listnode *now = new listnode;
now->ms = ms;
now->md = md;
now->from = from;
now->next = next;
if (from)
from->next = now;
if (next)
next->from = now;
if (from && from->md + 1 == now->ms) {
from->md = now->md;
from->next = now->next;
if (now->next)
now->next->from = from;
delete now;
now = from;
}
if (next && now->md + 1 == next->ms) {
now->md = next->md;
now->next = next->next;
if (next->next)
next->next->from = now;
delete next;
}
}
int main() {
freopen("memory.in", "r", stdin);
freopen("memory.out", "w", stdout);
int n, t, m, p;
cin >> n;
head = new listnode;
head->ms = 0;
head->md = n - 1;
head->next = NULL;
head->from = NULL;
while (1) {
cin >> t >> m >> p;
if (t == 0 && m == 0 && p == 0) {
break;
}
while (use.top().t <= t) {
for (auto i = head; i != NULL; i = i->next) {
if (use.top().ms < i->ms) {
add(use.top().ms, use.top().md, i->from, i);
break;
}
}
}
bool ok = 0;
for (auto i = head; i != NULL; i = i->next) {
int ms = i->ms, md = i->md;
listnode *next = i->next, *from = i->from;
if (md - ms + 1 >= m) {
use.push({ms, ms + m - 1, t + p});
ok = 1;
delete i;
if (md < ms + m - 1)
add(ms + m, md, from, next);
}
}
}
}