牛客网 牛客练习赛7 B.购物-STL(priority_queue)
空间限制:C/C++ 32768K,其他语言65536K
64bit IO Format: %lld
题目描述
那么问题来了,你最少需要多少钱才能达成自己的目的呢?
输入描述:
第一行两个正整数n和m,分别表示天数以及糖果店每天生产的糖果数量。
接下来n行(第2行到第n+1行),每行m个正整数,第x+1行的第y个正整数表示第x天的第y个糖果的费用。
输出描述:
输出只有一个正整数,表示你需要支付的最小费用。
输入
3 2
1 1
100 100
10000 10000
输出
107
输入
5 5
1 2 3 4 5
2 3 4 5 1
3 4 5 1 2
4 5 1 2 3
5 1 2 3 4
输出
10
备注:
对于100%的数据,1 ≤ n, m ≤ 300 , 所有输入的数均 ≤ 10^6。
1 #include<cstring>
2 #include<cstdio>
3 #include<algorithm>
4 #include<cmath>
5 #include<iostream>
6 #include<queue>
7 using namespace std;
8 typedef long long ll;
9 const int N=1e4+10;
10 int a[N][N];
11 priority_queue<int,vector<int>,greater<int> >gg;
12 int main(){
13 int n,m;
14 ll ans;
15 while(cin>>n>>m){
16 for(int i=1;i<=n;i++)
17 for(int j=1;j<=m;j++)
18 cin>>a[i][j];
19 for(int i=1;i<=n;i++)
20 sort(a[i]+1,a[i]+1+m);
21 for(int i=1;i<=n;i++){
22 int cnt=1;
23 for(int j=1;j<=m;j++){
24 a[i][j]+=cnt;
25 cnt+=2;
26 }
27 }
28 ans=0;
29 for(int j=1;j<=m;j++)
30 gg.push(a[1][j]);
31 ans+=gg.top();
32 gg.pop();
33 for(int i=2;i<=n;i++){
34 for(int j=1;j<=m;j++)
35 gg.push(a[i][j]);
36 ans+=gg.top();
37 gg.pop();
38 }
39 cout<<ans;
40 }
41 return 0;
42 }
一开始二维数组排序的通过了90%的数据,应该是卡在一组很大的数上了。
溜啦溜啦,还有一道珂朵莉的数列的树状数组+大数(高精度)没写出来,补题补题。
牛客网 牛客练习赛7 B.购物-STL(priority_queue)的更多相关文章
- 牛客网 牛客练习赛43 F.Tachibana Kanade Loves Game-容斥(二进制枚举)+读入挂
链接:https://ac.nowcoder.com/acm/contest/548/F来源:牛客网 Tachibana Kanade Loves Game 时间限制:C/C++ 1秒,其他语言2秒 ...
- 牛客网 牛客练习赛43 C.Tachibana Kanade Loves Review-最小生成树(并查集+Kruskal)+建虚点+读入挂
链接:https://ac.nowcoder.com/acm/contest/548/C来源:牛客网 Tachibana Kanade Loves Review 时间限制:C/C++ 2秒,其他语言4 ...
- 牛客网 牛客练习赛43 B.Tachibana Kanade Loves Probability-快速幂加速
链接:https://ac.nowcoder.com/acm/contest/548/B来源:牛客网 Tachibana Kanade Loves Probability 时间限制:C/C++ 1秒, ...
- 牛客网 牛客练习赛13 C.幸运数字Ⅲ-思维
C.幸运数字Ⅲ 链接:https://www.nowcoder.com/acm/contest/70/C来源:牛客网 这个题447和477是特殊的,其他的就没什么了. 代码: 1 #i ...
- 牛客网 牛客练习赛13 B.幸运数字Ⅱ-数组 or DFS
B.幸运数字Ⅱ 链接:https://www.nowcoder.com/acm/contest/70/B来源:牛客网 这个题就是找出来数据范围内的所有的幸运数,然后直接区间累加起来就可以了. ...
- 牛客网 牛客练习赛13 A.幸运数字Ⅰ
A.幸运数字Ⅰ 链接:https://www.nowcoder.com/acm/contest/70/A来源:牛客网 水题. 代码: #include<iostream> #i ...
- 牛客网 牛客练习赛11 D.求距离
D.求距离 链接:https://www.nowcoder.com/acm/contest/59/D来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒空间限制:C/C++ 32768K,其他语言6 ...
- 牛客网 牛客练习赛11 A.假的线段树
看不懂题意,而且太菜,写了两道就溜了... A.假的线段树 链接:https://www.nowcoder.com/acm/contest/59/A来源:牛客网 时间限制:C/C++ 1秒,其他语言2 ...
- 牛客网 牛客练习赛4 A.Laptop-二维偏序+离散化+树状数组
A.Laptop 链接:https://ac.nowcoder.com/acm/contest/16/A来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 131072K,其 ...
随机推荐
- VSX-2 搭建项目
由于是公司的项目,也不可能直接拿过来写博客,所以准备搭建一个自己的VSX项目. 项目需求这里就不写了,大体可参考曾经的一篇文章,这个VSX项目就是用来简化插件式开发. 本文开始正式记录做这个VSX项目 ...
- 《Cracking the Coding Interview》——第5章:位操作——题目4
2014-03-19 06:15 题目:解释(n & (n - 1)) == 0是什么意思? 解法:n&n-1是去掉最低位‘1’的方法.根据运算符优先级,貌似用不着加那个括号,但位运算 ...
- 【Lowest Common Ancestor of a Binary Tree】cpp
题目: Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. Accor ...
- ASP NET Core ---FluentValidation
官方文档:https://fluentvalidation.net/ 一.安装: 二.应用: 1.建立PostValidator: public class PostValidator:Abstrac ...
- 1106 Lowest Price in Supply Chain (25 分)(树的遍历)
求叶子结点处能活得最低价格以及能提供最低价格的叶子结点的个数 #include<bits/stdc++.h> using namespace std; ; vector<int> ...
- Set(), Get() 真正的目的
在各种面向对象编程中,都有 Set(), Get() 两种方法. 1 常见理解 1 为了保证安全性 2 为了规范代码 其实这些理解都是对的.具体看我们从哪个角度去理解这个内容. 2 个人理解 2.1 ...
- 网络--NAT技术
一.概述 1.简介 NAT英文全称是“Network Address Translation”,中文意思是“网络地址转换”,它是一个IETF(Internet Engineering Task For ...
- 爬虫:Scrapy16 - Spider Contracts
Scrapy 通过合同(contract)的方式来提供了测试 spider 的集成方法. 可以硬编码(hardcode)一个样例(sample)url,设置多个条件来测试回调函数处理 response ...
- 重复造轮子系列--内存池(C语言)
这个代码是我上个公司工作项目的里面内存管理(基于伙伴算法)的一个简化又简化的版本. 因为没有内存边界检查: 因为没有内存使用统计: 因为没有考虑线程安全: 因为没有内存分配操作的具体文件位置信息: 因 ...
- BATCH梯度下降,单变量线性回归