zoukankan      html  css  js  c++  java
  • Codeforces 853A Planning

    题意

    给出飞机单位晚点时间代价和原定起飞时间,现在前k分钟不能起飞,求付出的最小代价和起飞顺序

    思路

    构造两个优先队列q1,q2,q1按时间顺序,q2按代价顺序,初始将所有飞机入q1,将时间在k前的飞机从q1加入q2,然后按时间顺序取出q1加入q2,同时从q2取出代价最大的加入答案

    代码

    #include<bits/stdc++.h>
    using namespace std;
    inline int read(){
        int x = 0,f= 1; char ch = getchar();
        while(ch<'0' || ch>'9') {if(ch == '-') f=-1;ch = getchar();}
        while(ch>='0'&&ch<='9') {x = x*10+ch-'0';ch = getchar();}
        return x*f;
    }
    int n, k;
    long long ans;
    struct F{
        long long t;
        long long v;
        int ans;
        F(){}
        F(int a,int b){
            t = a, v = b;
        }
    }f[300100];
    struct CMPT{
        bool operator()(const F& a, const F& b){
            return a.t>b.t;
        }
    };
    struct CMPV{
        bool operator()(const F& a, const F& b){
            return a.v<b.v;
        }
    };
    priority_queue<F, vector<F>, CMPT> qt;
    priority_queue<F, vector<F>, CMPV> qv;
    int main(){
        scanf("%d%d",&n,&k);
        for(int i = 1;i<=n;i++) f[i] = F(i, read()), qt.push(f[i]);
        while(qt.top().t<=k && !qt.empty()){
            qv.push(qt.top());
            qt.pop();
        } 
        for(int i = k+1;i<=k+n;i++){
            if(!qt.empty()) qv.push(qt.top()), qt.pop();
            ans += (i-qv.top().t)*qv.top().v, f[qv.top().t].ans = i;
            qv.pop();
        }
        printf("%I64d
    ",ans);
        for(int i = 1;i<=n;i++) printf("%d%s",f[i].ans,(i == n?"
    ":" "));
        return 0;
    }
  • 相关阅读:
    idea主题更换pycharm/intellij
    随机生成n张扑克牌。
    JAVA生成6个1-8的随机数,要求无重复。
    一道简单 的循环
    linux虚拟机互访
    linux中grep命令
    vi和vim编辑器
    文件压缩打包以及备份
    文件内容查询
    目录相关操作
  • 原文地址:https://www.cnblogs.com/Invisible-full-moon/p/7580050.html
Copyright © 2011-2022 走看看