mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-12-24 03:31:59 +00:00
P5763 [NOI1999] 内存分配
R55180922
This commit is contained in:
parent
47073aef3b
commit
c7279f8669
88
Luogu/problem/P5763/P5763.cpp
Normal file
88
Luogu/problem/P5763/P5763.cpp
Normal file
@ -0,0 +1,88 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
struct node {
|
||||
int t, m, p, s;
|
||||
|
||||
bool operator<(const node& x) const {
|
||||
return s < x.s;
|
||||
}
|
||||
};
|
||||
|
||||
int n, t, m, p, w = 0x3f3f3f3f, ans, cnt;
|
||||
queue<node> wait;
|
||||
vector<node> mem;
|
||||
node x;
|
||||
|
||||
bool assign(int t) {
|
||||
if (mem.empty() || mem[0].s >= x.m) {
|
||||
x.s = 0;
|
||||
x.t = t;
|
||||
mem.push_back(x);
|
||||
sort(mem.begin(), mem.end());
|
||||
return true;
|
||||
}
|
||||
for (int i = 1; i < mem.size(); i++) {
|
||||
if (mem[i].s - (mem[i - 1].s + mem[i - 1].m) >= x.m) {
|
||||
x.s = mem[i - 1].s + mem[i - 1].m;
|
||||
x.t = t;
|
||||
mem.push_back(x);
|
||||
sort(mem.begin(), mem.end());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (n - ((--mem.end())->s + (--mem.end())->m) >= x.m) {
|
||||
x.s = (--mem.end())->s + (--mem.end())->m;
|
||||
x.t = t;
|
||||
mem.push_back(x);
|
||||
sort(mem.begin(), mem.end());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void release() {
|
||||
int nw = 0x3f3f3f3f;
|
||||
for (int i = 0; i < mem.size(); i++) {
|
||||
if (mem[i].t + mem[i].p == w) {
|
||||
mem.erase(mem.begin() + i--);
|
||||
} else {
|
||||
nw = min(nw, mem[i].t + mem[i].p);
|
||||
}
|
||||
}
|
||||
while (!wait.empty()) {
|
||||
x = wait.front();
|
||||
if (assign(w)) {
|
||||
nw = min(nw, wait.front().t + wait.front().p);
|
||||
wait.pop();
|
||||
cnt++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
w = nw;
|
||||
}
|
||||
|
||||
int main() {
|
||||
cin >> n;
|
||||
while (cin >> t >> m >> p, t || m || p) {
|
||||
while (t >= w) release();
|
||||
x.t = t;
|
||||
x.m = m;
|
||||
x.p = p;
|
||||
if (assign(t)) {
|
||||
w = min(w, t + p);
|
||||
} else {
|
||||
wait.push(x);
|
||||
}
|
||||
}
|
||||
while (!wait.empty()) release();
|
||||
ans = w;
|
||||
for (int i = 0; i < mem.size(); i++) {
|
||||
ans = max(ans, mem[i].t + mem[i].p);
|
||||
}
|
||||
cout << ans << endl
|
||||
<< cnt << endl;
|
||||
return 0;
|
||||
}
|
BIN
Luogu/problem/P5763/data/P5763_1.in
(Stored with Git LFS)
Normal file
BIN
Luogu/problem/P5763/data/P5763_1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/problem/P5763/data/P5763_1.out
(Stored with Git LFS)
Normal file
BIN
Luogu/problem/P5763/data/P5763_1.out
(Stored with Git LFS)
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user