分析:给你n个人M件衣服, 选出前K件衣服评价最大值,注意要输出的是编号,编号从大到小。两次排序即可。
#include<iostream>
#include<algorithm>
using namespace std;
struct node
{
double m;
int id;
};
bool cmp(const node& a,const node& b)
{
if(a.m!=b.m)
return a.m>b.m;
else
return a.id<b.id;
}
bool cmp2(const node& a,const node& b) //按照编号排序
{
return a.id>b.id;
}
int main()
{
int n,m,k;
double t;
int i;
node s[10000];
while(cin>>n>>m>>k)
{
for(i=0;i<m;i++)
s[i].m=0;
while(n--)
for(i=0;i<m;i++)
{
cin>>t;
s[i].m+=t;
s[i].id=i;
}
sort(s,s+m,cmp);
sort(s,s+k,cmp2);
for(i=0;i<k;i++)
{
cout<<s[i].id+1;
if(i<k-1)
cout<<' ';
}
cout<<endl;
}
return 0;
}
HDU ACM 1031 Design T-Shirt 水题
原文地址:http://blog.csdn.net/a809146548/article/details/46382113