Design T-shirt
Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 6527 Accepted Submission (s): 3061
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
Authorchen, Yue
Sourcecyjj ' s Funny Contest #1, killing in seconds gas my headache, ya eggs, although the legend of the simple problem, the topic on the one side to understand, the solution is clear, the tragedy in a very difficult to write, timeout, stack overflow ... Timeout...... Overflow ... wa nearly 30 times, and finally with the structure, with the sad is also the mother time out, more ridiculous is the structure of the sorting solution program to C immediately after, although stupid death can not bully people too much time wasted, but still feel learned a lot of things ; Take a look at these solutions: the first: Open three arrays: one to save n personal m data, one to save M summation data, another to record the first K support high program sequence number, side by step after the descending output; the second: the same as the first, except that the third array is not a value to record the ordinal, but the array subscript The third type: The first two, written to find the serial number and the sum of each program support is related, the structure is more convenient. One:
#include <iostream> #include <algorithm> #include <string.h>const int m=100;using namespace Std;bool CMP (int a,int b) {return a>b;} int main () {double ls[m][m];d ouble gq[m];int flag[m];int n,m,k,i,j,t;while (scanf ("%d%d%d", &n,&m,&k)) {int X=0;memset (Gq,0,sizeof (GQ)), memset (ls,0,sizeof (LS)), memset (flag,0,sizeof (flag)); for (i=0;i<n;i++) for (j=0;j <m;j++) {scanf ("%lf", &ls[i][j]); gq[j]+=ls[i][j];} while (k--) {int max=-1;for (int t=0;t<m;t++) {if (Gq[t]>max) {max=gq[t]; T =t;}} gq[t]=-1;flag[x++]=t+1;} Sort (flag,flag+x,cmp), for (int p=0;p<x-1;p++) printf ("%d", Flag[p]);p rintf ("%d\n", Flag[x-1]);} return 0;}
Second:
#include <iostream> #include <algorithm> #include <string.h>const int m=10000;using namespace Std;int Main () {double ls[m][m];d ouble gq[m];int flag[m];int n,m,k,i,j,t;while (scanf ("%d%d%d", &n,&m,&k)) {int x=0 , I=k;memset (Gq,0,sizeof (GQ)), memset (ls,0,sizeof (LS)), memset (flag,0,sizeof (flag)); for (i=0;i<n;i++) for (j=0;j <m;j++) {scanf ("%lf", &ls[i][j]); gq[j]+=ls[i][j];} while (k--) {int max=-1;for (int t=0;t<m;t++) {if (Gq[t]>max) {max=gq[t]; T =t;}} Gq[t]=-1;flag[t]=1;} for (int p=m-1;p>=0;p--) {if (flag[p]==1) {x++;if (x==i) {printf ("%d\n", p+1); elseprintf ("%d", p+1);}}} return 0;}
Third: AC Code:
#include <cmath> #include <iostream>using namespace std; #include <algorithm> #include <string.h >const int n=10005;struct ls{ int k; Double sum;} Gq[n];bool CMP1 (ls a,ls b) { return a.sum>b.sum;} BOOL CMP2 (LS A,ls b) { return A.K>B.K;} int main () { int n,m,k,i; double re; while (~SCANF ("%d%d%d", &n,&m,&k)) {for (i=0;i<m;i++) { gq[i].k=i; gq[i].sum=0.0; } for (int j=0;j<n;j++) for (int t=0;t<m;t++) { scanf ("%lf", &re); gq[t].sum+=re; } Sort (GQ,GQ+M,CMP1); Sort (GQ,GQ+K,CMP2); for (int w=0;w<k-1;w++) printf ("%d", gq[w].k+1); printf ("%d\n", gq[k-1].k+1); } return 0;}
Hangzhou Electric HDU 1031 Design T-shirt