zoukankan      html  css  js  c++  java
  • Design T-Shirt 排序

                                                                                                 Design T-Shirt

    Description

    Soon after he decided to design a T-shirt for our Algorithm Board on Free-City BBS, XKA found that he was trapped by all kinds of suggestions from everyone on the board. It is indeed a mission-impossible to have everybody perfectly satisfied. So he took a poll to collect people's opinions. Here are 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 into his design. He needs you to pick for him the K elements such that the total number of satisfaction is maximized. 
     

    Input

    The input consists of multiple test cases. For each case, the first line contains three positive integers N, M and K where N is the number of people, M is the number of design elements, and K is the number of elements XKA will 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. 
     

    Output

    For each test case, print in one line the indices of the K elements you would suggest XKA to take into consideration so that the total number of satisfaction is maximized. If there are more than one solutions, you must output the one with minimal indices. The indices start from 1 and must be printed in non-increasing order. There must be exactly one space between two adjacent indices, and no extra space at the end of the line. 
     

    Sample Input

    3 6 4 2 2.5 5 1 3 4 5 1 3.5 2 2 2 1 1 1 1 1 10 3 3 2 1 2 3 2 3 1 3 1 2
     

    Sample Output

    6 5 3 1 2 1
     

    #include<iostream>
    using namespace std;
    struct element{
        int number;
        double satisfaction;
    }s[100], a[100], b;
    int adjust(element s[], int low, int high) {
        b = s[low];
        double x = s[low].satisfaction;
        while(low < high){
            while(low < high && s[high].satisfaction > x) high--;
            if(low<high) { s[low] = s[high]; low++; }
            while(low < high && s[low].satisfaction < x) low++;
            if(low<high) { s[high] = s[low]; high--; }
        }
        s[low] = b;
        return low;
    }
    void qsort(element s[], int l, int r) {
        if(l < r){
            int i = adjust(s, l, r);
            qsort(s, l, i-1);
            qsort(s, i+1, r);
        }
    }
    int Adjust(element a[], int low, int high) {
        b = a[low];
        int x = a[low].number;
        while(low < high){
            while(low < high && a[high].number >= x) high--;
            if(low<high) { a[low] = a[high]; low++; }
            while(low < high && a[low].number <= x) low++;
            if(low<high) { a[high] = a[low]; high--; }
        }
        a[low] = b;
        return low;
    }
    void qqsort(element a[], int l, int r) {
        if(l < r){
            int i = Adjust(a, l, r);
            qqsort(a, l, i-1);
            qqsort(a, i+1, r);
        }
    }
    int main(){
        int n, m, k, i;
        while(cin>>n>>m>>k){
            for(i=0; i<m; i++){
                s[i].number = i+1;
                s[i].satisfaction = 0;
            }
            double y;
            for(i=0; i<n; i++)
                for(int j=0; j<m; j++)
                {
                    cin>>y;
                    s[j].satisfaction += y;
                }
            qsort(s, 0, m-1);
            int p=0;
            for(i=m-k; i<m; i++)
                a[p++] = s[i];
            qqsort(a, 0, k-1);
            for(i=k-1; i>=0; i--)
                i==k-1? cout<<a[i].number : cout<<" "<<a[i].number;
            cout<<endl;
        }
        return 0;
    }
    


  • 相关阅读:
    codeforces 459 B.Pashmak and Flowers 解题报告
    poj 1789 Truck History 解题报告
    poj 1258 Agri-Net 解题报告
    poj 1860 Currency Exchange 解题报告
    poj 1094 Sorting It All Out 解题报告
    poj 3368 Frequent values 解题报告
    hdu 1548 A strange lift 解题报告
    BestCoder4 1002 Miaomiao's Geometry (hdu 4932) 解题报告
    hdu 1400 Mondriaan's Dream 解题报告
    打电话主要代码(意图用法)
  • 原文地址:https://www.cnblogs.com/Genesis2018/p/9079900.html
Copyright © 2011-2022 走看看