Design T-shirt
Problem Descriptionsoon after he decided to design a T-shirt for we algorithm Board on free-city BBS, Xka found that he w As trapped by all kinds of suggestions from everyone on the board. It is indeed a mission-impossible to the everybody perfectly satisfied. So he took a poll to collect people ' s opinions. Here is what he obtained:n people voted for M design elements (such as the ACM-ICPC logo, big names in computer science, well-known graphs, etc.). Everyone assigned each element a number of satisfaction. However, Xka can only put K (<=m) elements to his design. He needs the pick for him, the K elements such, the total number of satisfaction are maximized.
Inputthe input consists of multiple test cases. For each case, the first line contains three positive integers n, m and K where N was the number of people, M is the number of design elements, and K is the number of elements Xka would put into his design. Then N lines follow, each contains M numbers. The j-th number in the I-th line represents the i-th person ' s satisfaction on the j-th element.
Outputfor each test case, print on one line the indices of the K elements you would suggest xka to take into consideration So, the total number of satisfaction is maximized. If there is more than one solutions, you must the output of the one with minimal indices. The indices start from 1 and must is printed in non-increasing order. There must be exactly one space between a adjacent indices, and no extra space at the end of the line.
Sample Input
3 6 42 2.5 5 1 3 45 1 3.5 2 2 21 1 1 1 1 103 3 21 2 32 3 13 1 2
Sample Output
6 5 3) 12 1
n Individuals, M-pieces of clothing, the output of the highest evaluation of the first K-pieces, the output, the evaluation of the same label large first output.
Be sure to have two rows, as all the evaluations are as high as possible, and there will be errors in the output only once.
The code is as follows:
#include <cstdio> #include <algorithm>using namespace std;struct ss{ double v; int x;}; BOOL Cmp1 (ss X,ss y) { if (X.V>Y.V) return true; else return false;} BOOL CMP2 (ss X,ss y) { if (x.x>y.x) return true; else return false;} int main () { int n,m,k; Double T; SS f[1010]; while (scanf ("%d%d%d", &n,&m,&k) ==3) {for (int i=0;i<m;i++) f[i].v=0; while (n--) for (int i=0;i<m;i++) { scanf ("%lf", &t); f[i].v+=t; f[i].x=i+1; } Sort (F,F+M,CMP1); Sort (F,F+K,CMP2);//two rows, row only K entry for (int i=0;i<k;i++) { if (i!=0) printf (""); printf ("%d", f[i].x); } printf ("\ n"); } return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
HDU 1031.Design T-shirt "structure two Orders" "August 21"