Hdu-1031-design T-shirt (c + + && simple Simulation)

Source: Internet
Author: User

Design T-shirtTime limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 6657 Accepted Submission (s): 3125


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
RECOMMENDIGNATIUS.L | We have carefully selected several similar problems for you:1036 1032 1033 1037 1039

Thanks to Fu students to share the idea, your algorithm is really exquisite incomparable ...
OK, let's talk about the main idea of the topic! (The score is not necessarily integral type)
Probably meaning is Xka intends to design a T-shirt, solicit public to this T-shirt satisfaction degree!
First enter three numbers: N,m,k (N indicates the number of points, M represents the total number of fractions, and K indicates the Xka to be selected)
Xka will choose the highest score of the first k elements, if the same score, select the front element!
Also note that the output format cannot have extra spaces.
Idea: 1. Compare the size of each column.
2. Record the number of columns after each comparison and maximum.
3. The size of the output column, if the number of columns is the same, the output of the front.
4. Format.

#include <iostream> #include <cstdio> #include <cstring> #define MAX 1000double a[300][300],b[300];    Using namespace Std;int main () {int m,n,k,i,j;                while (scanf ("%d%d%d", &n,&m,&k)!=eof) {for (i=0;i<n;i++) for (j=0;j<m;j++)           scanf ("%lf", &a[i][j]);            Enter the score for each person to play for (j=0;j<m;j++) {double sum=0;                    for (i=0;i<n;i++) {sum+=a[i][j];        Find out the scores of each column and each column corresponds to a topic} b[j]=sum;        } int F[max];        memset (F,0,sizeof (f));            for (i=0;i<k;i++) {double max=b[0];                        int flag = i; Record the maximum score and the subscript for (j=m-1;j>=0;j--) {if (max-b[j]<10e-6)//Compare to find the maximum score and                    The value, marked down {MAX=B[J];                Flag=j;            }} f[flag+1]=1;    b[flag]=0;                       Remove the maximum number of} int p=1;                for (i=max-1;i>=0;i--) {if (F[i]) {if (p) p=0;                 else printf ("");            Formatted output printf ("%d", I);    }} printf ("\ n"); } return 0;}




Hdu-1031-design T-shirt (c + + && simple Simulation)

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.