UVA 11997K Smallest Sums

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.