牛客网 牛客练习赛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,其 ...
随机推荐
- 剑指Offer - 九度1507 - 不用加减乘除做加法
剑指Offer - 九度1507 - 不用加减乘除做加法2013-11-29 20:00 题目描述: 写一个函数,求两个整数之和,要求在函数体内不得使用+.-.*./四则运算符号. 输入: 输入可能包 ...
- 《Cracking the Coding Interview》——第8章:面向对象设计——题目4
2014-04-23 18:17 题目:设计一个停车位的类. 解法:停车位,就要有停车.取车的功能了.另外我还加了一个工作线程用于计费,每秒给那些有车的车位加1块钱费用. 代码: // 8.4 Des ...
- .gitignore 中文文件夹无效
有个文件夹名如:测试 在.gitignore中添加 /测试/ 但运行命令git status后发现还是被追踪到了 一番搜索后终于发现.gitignore文件编码是GBK的,重新将文件保存成utf ...
- sql 表数据转移另一张表
if not exists(select * from syscolumns where id=object_id('REMOTEDETECTION_2018')) begin SELECT * I ...
- java单例模式(类只能创建唯一对象)
//饿汉式 class Single { private static final Single s= new Single(); private Single(){} public static S ...
- hadoop2.5.2学习及实践笔记(三)—— HDFS概念及体系结构
注:文中涉及的文件路径或配置文件中属性名称是针对hadoop2.X系列,相对于之前版本,可能有改动. 附: HDFS用户指南官方介绍: http://hadoop.apache.org/docs/r2 ...
- TypeScript & Angular
TypeScript https://github.com/Microsoft/TypeScript https://www.typescriptlang.org/ https://www.type ...
- DP石子合并问题
转自:http://www.hnyzsz.net/Article/ShowArticle.asp?ArticleID=735 [石子合并] 在一个圆形操场的四周摆放着n 堆石子.现要将石子有次序 ...
- P1270 “访问”美术馆
题目描述 经过数月的精心准备,Peer Brelstet,一个出了名的盗画者,准备开始他的下一个行动.艺术馆的结构,每条走廊要么分叉为两条走廊,要么通向一个展览室.Peer知道每个展室里藏画的数量,并 ...
- ubuntu系统更换源
一:问题概述 ubuntu,我们在使用apt新装软件的时候,会使用官方的网站去下载软件,但是会因为国内的转接点太多,而导致下载的速度非常慢 ,我们可以通过换成一些中间的节点来进行下载,比如阿里源,中科 ...