hihocoder1822 战舰日常任务
思路:
使用堆即可。
实现:
#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 战舰日常任务的更多相关文章
- tyvj1938 最优战舰
描述 太空战队顺利地完成了它的第一次使命,这一行动的受益者陆军本部当即决定,请陆军的战士们投票选出最优战舰并报司令总部进行表彰.为防止有人利用高科技手段造假,陆军本部决定使用最原始的方法进行投票.可不 ...
- STM32 (战舰)
一.战舰STM32 1.引脚描述表---有ft 兼容5V 2.原理图----有ADC,不兼容5V 3.(1)学会基本外设:GPIO输入输出,外部中断,定时器,串口. (2)学会外设接口:SPI IIC ...
- 51 nod 1521 一维战舰 时间复杂度O(n),同 Codeforces 567D. One-Dimensional Battle Ships 有详细注释
题目:51nod: 题目Codeforces: 题目注意到两个战舰不能挨在一起就可以了. // 每一段 struct node{ int left; // 段的左端点 int right; // 段的 ...
- 计蒜客NOIP模拟赛(2) D2T3 银河战舰
[问题描述] 瑞奥和玛德利德是非常好的朋友.瑞奥平时的爱好是吹牛,玛德利德的爱好是戳穿瑞奥吹的牛. 这天瑞奥和玛德利德来到了宇宙空间站,瑞奥向玛德利德炫耀这个空间站里所有的银河战舰都是自己 ...
- [Swift]LeetCode419. 甲板上的战舰 | Battleships in a Board
Given an 2D board, count how many battleships are in it. The battleships are represented with 'X's, ...
- 51Nod 1521 一维战舰
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1521 思路:先计算出一开始最多能放多少艘战舰,然后每次输入一个点后,找到 ...
- 【51nod-1521】一维战舰
爱丽丝和鲍博喜欢玩一维战舰的游戏.他们在一行有n个方格的纸上玩这个游戏(也就是1×n的表格). 在游戏开始的时候,爱丽丝放k个战舰在这个表格中,并不把具体位置告诉鲍博.每一只战舰的形状是 1×a 的长 ...
- Leetcode 419.甲板上的战舰
甲板上的战舰 给定一个二维的甲板, 请计算其中有多少艘战舰. 战舰用 'X'表示,空位用 '.'表示. 你需要遵守以下规则: 给你一个有效的甲板,仅由战舰或者空位组成. 战舰只能水平或者垂直放置.换句 ...
- 谁才是最强战舰!-From 南京理工大学第八届程序设计大赛(校外镜像),博弈~~
谁才是最强战舰! Time Limit: 1000MS Memory Limit: 65536KB Description 依阿华来到镇守府的第一件事情,就是找大和solo!然而这并不是什么好消息,说 ...
随机推荐
- [SDOI2012]任务安排
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=2726 [算法] 此题与POJ1180非常相似 但是 , 此题中的t值可能为负 , 这 ...
- ab-如何提交post请求
ab -n 1 -c 1 -p post.txt http://***********/ 文件post.txt中存放要post的数据
- 激活层和pooling的作用
激活层: 激活函数其中一个重要的作用是加入非线性因素的,将特征映射到高维的非线性区间进行解释,解决线性模型所不能解决的问题 pooling层: 1. invariance(不变性),这种不变性包括tr ...
- 构建一个简单的Angular工程
1.创建一个空的工程,之后用webstorm打开,添加一个bower.json文件: { "name": "AngularTpl", "depende ...
- 【旧文章搬运】NtGlobalFlags
原文发表于百度空间,2010-08-06========================================================================== - NtG ...
- ImportCommon
using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using S ...
- 二级ul li元素动态加载click事件
一.代码 html代码: <ul class="id1" id="id1" style="width:84%; height:75%;overf ...
- IOS实时监控上传下载速度
在开发中要获取网络类型是很简单的,导入Reachability直接获取状态就行了,现在我们要做一个类似下载器的那种实时把上传下载速度显示出来. 需要用到的头文件 使用Reachability 要测速度 ...
- Git之通过ssh clone代码
1.git平台:码云 2.服务器系统:Linux 1.在Linux中创建ssh公钥,将创建的公钥添加到码云的ssh公钥管理 2.一般来说我们配置完站点之后,都会生成一个站点对应的文件夹,进入文件夹,然 ...
- C#箴言:定义常量的两种方法
在C#中定义常量的方式有两种, 一种叫做静态常量(Compile-time constant),另一种叫做动态常量(Runtime constant). 前者用"const"来定义 ...