上链接:杭电1031
题目大意:
给出N个人对M个元素的满意度,需要添加K个元素到T-shirt上,使得满意度最大。
贴代码:
#include <cstdio>
#include <algorithm>
using namespace std;
struct tshirt
{
double num;
int c;
}b[500];
double a[500][500];
bool cmp1(tshirt a, tshirt b)
{
return a.num>b.num;
}
bool cmp2(int a, int b)
{
return a>b;
}
int main()
{
int n, m, k;
int answer[1000];
while(scanf("%d %d %d", &n, &m, &k) != EOF)
{
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].num = 0;
b[i].c = i + 1;
for(int j=0; j<n; ++j)
b[i].num += a[j][i];
}
sort(b, b+m, cmp1);
for(int i=0; i<k; ++i)
answer[i] = b[i].c;
sort(answer, answer+k, cmp2);
for(int i=0; i<k; ++i)
if(i != k-1)
printf("%d ", answer[i]);
else
printf("%d\n", answer[i]);
}
return 0;
}