hdu1031Design T-Shirt

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1031

这道题的坑就在于 序号从1开始 但是 不一定要有1号。。。

代码:
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;
#define maxn 1000

double a[maxn + 3][maxn + 3];
int c[maxn + 3];
struct total
{
    double score;
    int cur;
}b[maxn];


bool cmp(struct total x,struct total y)

{
    if(x.score != y.score)
        return x.score > y.score;
    else
        return x.cur < y.cur;
}

int main()

{
    int n,m,k;
    while(~scanf("%d%d%d",&n,&m,&k))
    {
        memset(b,0,sizeof b);
        memset(c,0,sizeof c);
        for(int i = 0;i < n;++i)
            for(int j = 0;j < m;++j)
                scanf("%lf",&a[i][j]);
        for(int i = 0;i < m;++i){
            b[i].cur = i;
            for(int j = 0;j < n;++j)
                b[i].score += a[j][i];
        }
        sort(b,b + m,cmp);
        //for(int i = 0;i < m;++i)
          //  printf("%lf %d\n",b[i].score,b[i].cur);
        for(int i = 0;i < k;++i)
            c[i] = b[i].cur;
        sort(c,c + k);
        for(int i = k - 1;i >= 0;--i)
            if(i == k - 1)
               printf("%d",c[i]+1);
            else
                printf(" %d",c[i]+1);
        printf("\n");
    }
    return 0;
}

你可能感兴趣的:(ACM)