zoukankan      html  css  js  c++  java
  • 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;
    }
    

      

  • 相关阅读:
    mybatis源码追踪2——将结果集映射为map
    Mybatis的cache
    mybatis拦截器
    mybatis中单个参数的引用
    mybatis源码追踪1——Mapper方法用法解析
    win8 下 intellij idea 13 中文输入覆盖的问题
    firebug中html显示为灰色的原因总结
    extjs4.0以上添加多行工具栏的方法
    去除eclipse的validating
    An interview question from MicroStrategy
  • 原文地址:https://www.cnblogs.com/YDDDD/p/10387735.html
Copyright © 2011-2022 走看看