Test instructions: Xka to design t-shirt, solicit the public satisfaction of each element. Enter 3 integers, respectively, to N, M, K, where n represents the number of participants in the score, M represents the total number of elements, and K represents the number of elements to be selected for Xka. Xka will select the highest score of the first k elements, if the same score, choose the index of small elements.
Idea: Record the total number of each m and index, with the structure of the storage, two times the sort is enough
Also note that the output format cannot have extra spaces.
1#include <iostream>2#include <algorithm>3#include <cmath>4 using namespacestd;5 Doublenum[1005][1005];6 structpoint{7 Doubletot;8 intindex;9}p[1005];Ten intx[1050]; One intCMP (point x,point y) A { - returnX.tot>Y.tot; - } the intCop (point A,point b) - { - returnA.index>B.index; - } + intMain () - { + intn,m,k; A while(SCANF (" %d%d%d", &n,&m,&k)! =EOF) { at for(intJ,i=1; i<=n;++i) - for(j=1; j<=m;++j) -scanf"%LF",&num[i][j]); - intt=0; - for(inti,j=1; j<=m;++j) { - Doublesum=0; in for(i=1; i<=n;++i) -sum+=Num[i][j]; top[t].tot=sum; +p[t].index=J; -++T; the } *Sort (p,p+t,cmp); $Sort (p,p+K,cop);Panax Notoginsengprintf"%d", p[0].index); - for(intI=1; i<k;++i) theprintf"%d", P[i].index); +printf"\ n"); A } the}
HDU 1031 Design T-shirt