zoukankan      html  css  js  c++  java
  • hihocoder1822 战舰日常任务

    思路:

    使用堆即可。

    实现:

     1 #include <iostream>
     2 #include <map>
     3 #include <vector>
     4 #include <cstring>
     5 #include <queue>
     6 #include <algorithm>
     7 
     8 using namespace std;
     9 
    10 typedef pair<int, int> pii;
    11 
    12 int buf[6], need[6][10005];
    13 
    14 int main()
    15 {
    16     int T, n, m;
    17     cin >> T;
    18     map<string, int> mp;
    19     mp["CV"] = 0; mp["DD"] = 1; mp["CL"] = 2;
    20     mp["CA"] = 3; mp["BB"] = 4; mp["BC"] = 5;
    21     while (T--)
    22     {
    23         memset(need, 0, sizeof need);
    24         cin >> n >> m;
    25         string s;
    26         int l, f;
    27         vector<pii> v[6];
    28         for (int i = 0; i < n; i++)
    29         {
    30             cin >> s >> l >> f;
    31             v[mp[s]].push_back(pii(l, f));
    32         }
    33         for (int i = 0; i < 6; i++) sort(v[i].begin(), v[i].end());
    34         for (int i = 0; i < m; i++)
    35         {
    36             for (int j = 0; j < 6; j++) cin >> buf[j];
    37             cin >> l;
    38             for (int j = 0; j < 6; j++)
    39             {
    40                 need[j][l] += buf[j];
    41             }
    42         }
    43         bool flg = true;
    44         int ans = 0;
    45         for (int i = 0; i < 6; i++)
    46         {
    47             priority_queue<int, vector<int>, greater<int>> q;
    48             for (int j = 10000; j >= 1; j--)
    49             {
    50                 if (need[i][j])
    51                 {
    52                     while (!v[i].empty() && v[i].back().first >= j)
    53                     {    
    54                         q.push(v[i].back().second);
    55                         v[i].pop_back();
    56                     }
    57                     if (q.size() < need[i][j]) { flg = false; break; }
    58                     while (need[i][j]) { ans += q.top(); q.pop(); need[i][j]--; }
    59                 }                
    60             }
    61             if (!flg) break;
    62         }
    63         if (!flg) cout << -1 << endl;
    64         else cout << ans << endl;
    65     }
    66     return 0;
    67 }
  • 相关阅读:
    Path文件操作实例
    Cache缓存对象缓存对象
    Session对象实例
    移动端适配问题
    webpack4 优化性能
    webpack源码分析
    wepack源码解析1
    webpack面试题
    asnyc await
    node 知识
  • 原文地址:https://www.cnblogs.com/wangyiming/p/9862776.html
Copyright © 2011-2022 走看看