Topic Links:
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem= 3148
Test instructions: Given k arrays, each array of k numbers, requires each number to elect a number, composition and, such a common KK case, requires the output of the smallest K and
In fact, as long as you can find out 2 of the first k values, and then continue to 22 merger can be
Code:
#include <stdio.h>#include <iostream>#include <algorithm>#include <string.h>#include <queue>#include <stack>#include <vector>using namespace STD;structitem{ints, b; Item (intSintb): s (s), B (b) {}BOOL operator< (Constitem& RHS)Const{returns > rhs.s; }};Const intMAXN =1100;intA[MAXN][MAXN];intB[MAXN];voidMergeintAintBintCintN) {priority_queue<item> q; for(inti =0; I < n; i++) Q.push (Item (a[i] + b[0],0)); for(inti =0; I < n; i++) {Item item = Q.top (); Q.pop (); C[i] = ITEM.S;intb = item.b;if(b +1< n) Q.push (Item (C[i]-b[b] + b[b+1], B +1)); }}intMain () {intN while(scanf("%d", &n)! = EOF) { for(inti =0; I < n; i++) { for(intj =0; J < N; J + +)scanf("%d", &a[i][j]); Sort (A[i], a[i] + N); } for(inti =1; I < n; i++) {Merge (a[0], A[i], B, N); for(intII =0; II < n; ii++) a[0][II] = B[ii]; }printf("%d", a[0][0]); for(inti =1; I < n; i++)printf("%d", a[0][i]);printf("\ n"); }return 0;}
Copyright NOTICE: Reprint please indicate the source.
UVA 11997K Smallest Sums