B.小A与任务

链接:https://ac.nowcoder.com/acm/contest/369/B

题意:

小A手头有 n 份任务,他可以以任意顺序完成这些任务,只有完成当前的任务后,他才能做下一个任务
第 i 个任务需要花费   xixi 的时间,同时完成第 i 个任务的时间不能晚于 yiyi ,时间掌控者向小A提出了一个条件:如果完成第 i 个任务的时间本应是 t ,但小A支付 m 个金币的话,他可以帮助小A在 tm×zit−m×zi  时刻完成第 i 个任务, zizi 是时间参数,会在输入中给出
小A想按时完成所有任务,请你帮他制定一个花费金币最少的方案

注意:不能使得某个任务的花费时间小于 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;
}

  

转载于:https://www.cnblogs.com/YDDDD/p/10387735.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值