行业网站系统,产品网站建设必要性,企业管理培训课程好卖吗,esuwiki wordpress题意#xff1a;K个数组每组K个值#xff0c;每次从一组中选一个#xff0c;共K^k种#xff0c;问前K个小的。 思路#xff1a;优先队列处理多路归并#xff0c;每个状态含有K个元素。详见刘汝佳算法指南。 1 #includeiostream2 #includecstdio3 #includ…题意K个数组每组K个值每次从一组中选一个共K^k种问前K个小的。 思路优先队列处理多路归并每个状态含有K个元素。详见刘汝佳算法指南。 1 #includeiostream2 #includecstdio3 #includecstdlib4 #includestack5 #includequeue6 #includevector7 #includemap8 #includealgorithm9 using namespace std;
10 int n;
11 int a[1000][1000];
12 int b[1000];
13 int c[1000];
14
15 struct Item
16 {
17 int s,b;
18 Item(int s,int b):s(s),b(b)
19 {
20 }
21 bool operator (const Item rhs) const
22 {
23 return srhs.s;
24 }
25 };
26 void merge(int *a,int *b,int *c,int n)
27 {
28 priority_queueItemq;
29 for(int i0; in; i)
30 q.push(Item(a[i]b[0],0));
31 for(int i0; in; i)
32 {
33 Item item q.top();
34 q.pop();
35 c[i]item.s;
36 int Bitem.b;
37 if(B1n)
38 q.push(Item(item.s-b[B]b[B1],B1));
39 }
40 }
41
42 int main()
43 {
44 while(~scanf(%d,n))
45 {
46 for(int i0; in; i)
47 {
48 for(int j0; jn; j)
49 scanf(%d,a[i][j]);
50 sort(a[i],a[i]n);
51 }
52 for(int i1; in; i)
53 merge(a[0],a[i],a[0],n);
54 printf(%d,a[0][0]);
55 for(int i1; in; i)
56 printf( %d,a[0][i]);
57 printf(\n);
58 }
59 return 0;
60 } View Code 转载于:https://www.cnblogs.com/ITUPC/p/5076307.html