标签:typedef https http space .com 1.0 cpp print 选择
注意:不能使得某个任务的花费时间小于 0 ,花费的金币可以不是整数
按照截至时间排序,没选到一个将其压入一个优先队列,以z优先原则。
当世时间不够时,选择z最大的来花费。同时每个有最大的花费额,当最大花费时间用完时,就不能使用。
//优先队列的结构体排序与sort相反。that为优先。
#include <bits/stdc++.h> using namespace std; typedef long long LL; const int MAXN = 2e5 + 10; struct Node { int _x; int _y; double _z; bool operator < (const Node & that) const { return this->_y < that._y; } }node[MAXN]; struct Eage { int _x; int _z; bool operator < (const Eage & that) const { return this->_z < that._z; } Eage(int x, int z):_x(x), _z(z) {}; }; priority_queue<Eage> que; int main() { int n; cin >> n; for (int i = 1;i <= n;i++) cin >> node[i]._z >> node[i]._x >> node[i]._y; sort(node + 1, node + 1 + n); double res = 0; int w = 0; for (int i = 1;i <= n;i++) { que.emplace(node[i]._x, node[i]._z); w += node[i]._x; while (w > node[i]._y) { Eage now = que.top(); que.pop(); int time = w - node[i]._y; time = min(time, now._x); w -= time; now._x -= time; res += 1.0 * time / now._z; if (now._x > 0) que.push(now); } } printf("%.1lf", res); return 0; }
标签:typedef https http space .com 1.0 cpp print 选择
原文地址:https://www.cnblogs.com/YDDDD/p/10387735.html