zoukankan      html  css  js  c++  java
  • Codeforces Round #433 (Div. 1, based on Olympiad of Metropolises) A. Planning 优先队列

    链接:

    http://codeforces.com/contest/853/problem/A

    题意:

    飞机场原定计划从第一分钟开始每分钟起飞一架飞机,但是由于某些原因导致前k分钟无法起飞飞机。给出每架飞机每延误一分钟的损失costi,问所有飞机都起飞后的最小损失为多少

    思路:

    对于k+1到k+n的每一时刻,每次把将要延误的所有飞机加入队列中,然后取出cost最大的,让其在这个时刻起飞,最后所得的答案就是最小的损失

    代码:

    31 int n, k;
    32 int c[MAXN];
    33 int ans[MAXN];
    34 priority_queue<PII> que;
    35 
    36 int main() {
    37     ios::sync_with_stdio(false), cin.tie(0);
    38     cin >> n >> k;
    39     rep(i, 1, n + 1) cin >> c[i];
    40     rep(i, 1, k + 1) que.push(mp(c[i], i));
    41     ll sum = 0;
    42     rep(i, k + 1, k + 1 + n) {
    43         if (i <= n) que.push(mp(c[i],i));
    44         PII now = que.top();
    45         que.pop();
    46         sum += (ll)(i - now.second)*now.first;
    47         ans[now.second] = i;
    48     }
    49     cout << sum << endl;
    50     rep(i, 1, n + 1) cout << ans[i] << ' ';
    51     return 0;
    52 }
  • 相关阅读:
    Bluedroid介绍
    Android蓝牙介绍
    Android Bluetooth抓包
    Bluetooth LMP介绍
    Bluetooth Baseband介绍
    Bluetooth SDP介绍
    Bluetooth HFP介绍
    Bluetooth RFCOMM介绍
    Bluetooth L2CAP介绍
    Windows开发
  • 原文地址:https://www.cnblogs.com/baocong/p/7490220.html
Copyright © 2011-2022 走看看