思路:

使用堆即可。

实现:

 #include <iostream>
#include <map>
#include <vector>
#include <cstring>
#include <queue>
#include <algorithm> using namespace std; typedef pair<int, int> pii; int buf[], need[][]; int main()
{
int T, n, m;
cin >> T;
map<string, int> mp;
mp["CV"] = ; mp["DD"] = ; mp["CL"] = ;
mp["CA"] = ; mp["BB"] = ; mp["BC"] = ;
while (T--)
{
memset(need, , sizeof need);
cin >> n >> m;
string s;
int l, f;
vector<pii> v[];
for (int i = ; i < n; i++)
{
cin >> s >> l >> f;
v[mp[s]].push_back(pii(l, f));
}
for (int i = ; i < ; i++) sort(v[i].begin(), v[i].end());
for (int i = ; i < m; i++)
{
for (int j = ; j < ; j++) cin >> buf[j];
cin >> l;
for (int j = ; j < ; j++)
{
need[j][l] += buf[j];
}
}
bool flg = true;
int ans = ;
for (int i = ; i < ; i++)
{
priority_queue<int, vector<int>, greater<int>> q;
for (int j = ; j >= ; j--)
{
if (need[i][j])
{
while (!v[i].empty() && v[i].back().first >= j)
{
q.push(v[i].back().second);
v[i].pop_back();
}
if (q.size() < need[i][j]) { flg = false; break; }
while (need[i][j]) { ans += q.top(); q.pop(); need[i][j]--; }
}
}
if (!flg) break;
}
if (!flg) cout << - << endl;
else cout << ans << endl;
}
return ;
}

hihocoder1822 战舰日常任务的更多相关文章

  1. tyvj1938 最优战舰

    描述 太空战队顺利地完成了它的第一次使命,这一行动的受益者陆军本部当即决定,请陆军的战士们投票选出最优战舰并报司令总部进行表彰.为防止有人利用高科技手段造假,陆军本部决定使用最原始的方法进行投票.可不 ...

  2. STM32 (战舰)

    一.战舰STM32 1.引脚描述表---有ft 兼容5V 2.原理图----有ADC,不兼容5V 3.(1)学会基本外设:GPIO输入输出,外部中断,定时器,串口. (2)学会外设接口:SPI IIC ...

  3. 51 nod 1521 一维战舰 时间复杂度O(n),同 Codeforces 567D. One-Dimensional Battle Ships 有详细注释

    题目:51nod: 题目Codeforces: 题目注意到两个战舰不能挨在一起就可以了. // 每一段 struct node{ int left; // 段的左端点 int right; // 段的 ...

  4. 计蒜客NOIP模拟赛(2) D2T3 银河战舰

    [问题描述]    瑞奥和玛德利德是非常好的朋友.瑞奥平时的爱好是吹牛,玛德利德的爱好是戳穿瑞奥吹的牛.    这天瑞奥和玛德利德来到了宇宙空间站,瑞奥向玛德利德炫耀这个空间站里所有的银河战舰都是自己 ...

  5. [Swift]LeetCode419. 甲板上的战舰 | Battleships in a Board

    Given an 2D board, count how many battleships are in it. The battleships are represented with 'X's, ...

  6. 51Nod 1521 一维战舰

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1521 思路:先计算出一开始最多能放多少艘战舰,然后每次输入一个点后,找到 ...

  7. 【51nod-1521】一维战舰

    爱丽丝和鲍博喜欢玩一维战舰的游戏.他们在一行有n个方格的纸上玩这个游戏(也就是1×n的表格). 在游戏开始的时候,爱丽丝放k个战舰在这个表格中,并不把具体位置告诉鲍博.每一只战舰的形状是 1×a 的长 ...

  8. Leetcode 419.甲板上的战舰

    甲板上的战舰 给定一个二维的甲板, 请计算其中有多少艘战舰. 战舰用 'X'表示,空位用 '.'表示. 你需要遵守以下规则: 给你一个有效的甲板,仅由战舰或者空位组成. 战舰只能水平或者垂直放置.换句 ...

  9. 谁才是最强战舰!-From 南京理工大学第八届程序设计大赛(校外镜像),博弈~~

    谁才是最强战舰! Time Limit: 1000MS Memory Limit: 65536KB Description 依阿华来到镇守府的第一件事情,就是找大和solo!然而这并不是什么好消息,说 ...

随机推荐

  1. 记SCOI2017

    Day1完挂,OI再见. 居然卡进去了. UESTC的评测机见鬼啊,我本地不到1s.时限是3s的两道题都T了,然后就少了50pt. Day1 T1看完首先O(n^2)DP是裸的,然后感觉n选k好像不能 ...

  2. 利用Powershell在IIS上自动化部署网站

    本文主要讲如何通过Powershell在IIS上自动化部署ASP.NET网站,而不涉及Powershell的基本语法,如果没有Powershell基础的同学也可以把本文作为学习Powershell的基 ...

  3. Spark Streaming之二:StreamingContext解析

    1.1 创建StreamingContext对象 1.1.1通过SparkContext创建 源码如下: def this(sparkContext: SparkContext, batchDurat ...

  4. 动态规划专题(一) HDU1087 最长公共子序列

    Super Jumping! Jumping! Jumping! 首先对于动态规划问题要找出其子问题,如果找的子问题是前n个序列的最长上升子序列,但这样的子问题不好,因为它不具备无后效性,因为它的第n ...

  5. layui 复选框checkbox 全选写法

    前语:本来我是不想写layui框架的博客的,有的时候数据经过layui渲染后原生的写法就取不到值了,一定要用它框架的写法,实在蛋疼,故写之,以后用到可以省点时间去度娘! HTML: <div i ...

  6. Ubuntu 下编译libjingle-0.6.14 (转载)

    转自:http://blog.csdn.net/feifei454498130/article/details/8197103 添加依赖库: sudo apt-get install build-es ...

  7. window.showModalDialog 在谷歌Uncaught TypeError: undefined is not a function

    if(navigator.userAgent.indexOf("Chrome") >0 ){var winOption = "height="+heigh ...

  8. JQuery学习笔记(三)遍历 DOM

    遍历 DOM jQuery 提供了多种遍历 DOM 的方法.遍历方法中最大的种类是树遍历(tree-traversal). 向上父节点parent,向下子节点child,同胞next和pre 缩写搜索 ...

  9. Mac Apache

    参考文章1 当前系统版本:Mac OS 10.11.6 一.使用 homebrew 安装 apache 停止系统自带的 apache 服务 $ sudo apachectl stop 卸载系统自带的 ...

  10. 无法序列化会话状态。请注意,当会话状态模式为“StateServer”或“SQLServer”时,不允许使用无法序列化的对象或 MarshalByRef 对象。

    原文链接:http://blog.csdn.net/byondocean/article/details/7564502 session是工作在你的应用程序进程中的.asp.net进程.iis往往会在 ...