题目链接:https://www.nowcoder.com/practice/5727b69bf80541c98c06ab90cf4c509e?tpId=101&tqId=33102&tPage=1&rp=1&ru=/ta/programmer-code-interview-guide&qru=/ta/programmer-code-interview-guide/question-ranking

题目大意:

  略。

分析:

  坑1:数组内元素个数可能为0
  坑2:元素总个数可能不满K个

代码如下:

 #include <bits/stdc++.h>
using namespace std; #define INIT() ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define Rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define For(i,s,t) for (int i = (int)(s); i <= (int)(t); ++i)
#define rFor(i,t,s) for (int i = (int)(t); i >= (int)(s); --i)
#define ForLL(i, s, t) for (LL i = LL(s); i <= LL(t); ++i)
#define rForLL(i, t, s) for (LL i = LL(t); i >= LL(s); --i)
#define foreach(i,c) for (__typeof(c.begin()) i = c.begin(); i != c.end(); ++i)
#define rforeach(i,c) for (__typeof(c.rbegin()) i = c.rbegin(); i != c.rend(); ++i) #define pr(x) cout << #x << " = " << x << " "
#define prln(x) cout << #x << " = " << x << endl #define LOWBIT(x) ((x)&(-x)) #define ALL(x) x.begin(),x.end()
#define INS(x) inserter(x,x.begin())
#define UNIQUE(x) x.erase(unique(x.begin(), x.end()), x.end())
#define REMOVE(x, c) x.erase(remove(x.begin(), x.end(), c), x.end()); // 删去 x 中所有 c
#define TOLOWER(x) transform(x.begin(), x.end(), x.begin(),::tolower);
#define TOUPPER(x) transform(x.begin(), x.end(), x.begin(),::toupper); #define ms0(a) memset(a,0,sizeof(a))
#define msI(a) memset(a,0x3f,sizeof(a))
#define msM(a) memset(a,-1,sizeof(a)) #define MP make_pair
#define PB push_back
#define ft first
#define sd second template<typename T1, typename T2>
istream &operator>>(istream &in, pair<T1, T2> &p) {
in >> p.first >> p.second;
return in;
} template<typename T>
istream &operator>>(istream &in, vector<T> &v) {
for (auto &x: v)
in >> x;
return in;
} template<typename T>
ostream &operator<<(ostream &out, vector<T> &v) {
Rep(i, v.size()) out << v[i] << " \n"[i == v.size() - ];
return out;
} template<typename T1, typename T2>
ostream &operator<<(ostream &out, const std::pair<T1, T2> &p) {
out << "[" << p.first << ", " << p.second << "]" << "\n";
return out;
} inline int gc(){
static const int BUF = 1e7;
static char buf[BUF], *bg = buf + BUF, *ed = bg; if(bg == ed) fread(bg = buf, , BUF, stdin);
return *bg++;
} inline int ri(){
int x = , f = , c = gc();
for(; c<||c>; f = c=='-'?-:f, c=gc());
for(; c>&&c<; x = x* + c - , c=gc());
return x*f;
} template<class T>
inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
} inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
} //min <= aim <= max
template<typename T>
inline bool BETWEEN(const T aim, const T min, const T max) {
return min <= aim && aim <= max;
} typedef unsigned int uI;
typedef long long LL;
typedef unsigned long long uLL;
typedef vector< int > VI;
typedef vector< bool > VB;
typedef vector< char > VC;
typedef vector< double > VD;
typedef vector< string > VS;
typedef vector< LL > VL;
typedef vector< VI > VVI;
typedef vector< VB > VVB;
typedef vector< VS > VVS;
typedef vector< VL > VVL;
typedef vector< VVI > VVVI;
typedef vector< VVL > VVVL;
typedef pair< int, int > PII;
typedef pair< LL, LL > PLL;
typedef pair< int, string > PIS;
typedef pair< string, int > PSI;
typedef pair< string, string > PSS;
typedef pair< double, double > PDD;
typedef vector< PII > VPII;
typedef vector< PLL > VPLL;
typedef vector< VPII > VVPII;
typedef vector< VPLL > VVPLL;
typedef vector< VS > VVS;
typedef map< int, int > MII;
typedef unordered_map< int, int > uMII;
typedef map< LL, LL > MLL;
typedef map< string, int > MSI;
typedef map< int, string > MIS;
typedef multiset< int > mSI;
typedef multiset< char > mSC;
typedef set< int > SI;
typedef stack< int > SKI;
typedef stack< char > SKC;
typedef deque< int > DQI;
typedef queue< int > QI;
typedef priority_queue< int > PQIMax;
typedef priority_queue< int, VI, greater< int > > PQIMin;
const double EPS = 1e-;
const LL inf = 0x7fffffff;
const LL infLL = 0x7fffffffffffffffLL;
const LL mod = 1e9 + ;
const int maxN = 1e5 + ;
const LL ONE = ;
const LL evenBits = 0xaaaaaaaaaaaaaaaa;
const LL oddBits = 0x5555555555555555; int N, T, K;
VVI arrs;
VI p;
priority_queue< PII > Q;
VI ans; int main() {
//freopen("MyOutput.txt","w",stdout);
//freopen("input.txt","r",stdin);
//INIT();
scanf("%d%d", &T, &K);
arrs.resize(T);
p.resize(T); Rep(i, T) {
scanf("%d", &N);
p[i] = N - ;
Rep(j, N) {
int x;
scanf("%d", &x);
arrs[i].PB(x);
} if(p[i] >= ) Q.push(MP(arrs[i][p[i]--], i));
} Rep(i, K) {
if(Q.empty()) break;
PII tmp = Q.top(); Q.pop(); printf("%d%c", tmp.ft, " \n"[i == K - ]); if(p[tmp.sd] >= ) {
Q.push(MP(arrs[tmp.sd][p[tmp.sd]--], tmp.sd));
}
}
return ;
}

最新文章

  1. css控制文本框的只读属性的方法
  2. Java面试题之J2EE是什么
  3. 首先看K一个难看的数字
  4. 使WiFi具有保存历史连接的功能
  5. oracle学习 笔记(1)
  6. Eclipse常用快捷键记录
  7. Java反射-高级知识掌握
  8. python之路--day13---函数--三元表达式,递归,匿名函数,内置函数-----练习
  9. 点击编辑table变为可编辑状态
  10. 关于 someone could be eavesdropping on you right now (man-in-the-middle attack) ssh的解决办法
  11. nginx部分实现原理解析
  12. BZOJ3377 [Usaco2004 Open]The Cow Lineup 奶牛序列 其他
  13. 四则运算 python
  14. modelform的简介
  15. php 验证码 图像存在错误 无法显示 解决方法
  16. 网络传输---HttpURLConnection
  17. 用户组修改工具samusrgrp
  18. php解析mpp文件中的多级任务
  19. Root :: AOAPC I: Beginning Algorithm Contests (Rujia Liu) Volume 5. Dynamic Programming
  20. tcpdump 和 wireshark 的实用例子

热门文章

  1. base64加密原理
  2. JavaScript中Number(),parseInt()和parseFloat()区别
  3. JavaEE高级-通用Mapper学习笔记
  4. 洛谷P3158 [CQOI2011]放棋子 组合数学+DP
  5. php内置函数分析之ucwords()
  6. CF671D Roads in Yusland
  7. centos 6.5 安装 jdk 8
  8. NOIP2015 提高组 Day T3 斗地主
  9. Prometheus + Node Exporter + Grafana 监控主机运行信息
  10. Task8.循环和递归神经网络