您的位置:首页 > 其它

HDU 1031 Design T-Shirt

2013-11-29 18:04 387 查看
http://acm.hdu.edu.cn/showproblem.php?pid=1031

题意 :n个人,每个人对m件衣服打分,每个人对第 i 件衣服的打分要加起来,选取和前 k 高的输出他们的编号 i ,然后这k个的序号要倒序输出

思路 :快排一下就行了。这道题坑了我好几遍TLE,原因是我交的语言是G++而不是C++。。。。。。

#include <iostream>
#include <algorithm>
#include <stdio.h>
using namespace std ;
struct node
{
double sati ;
int order ;
} a[11100] ;
bool cmp(const node &x,const node &y)
{
return x.sati == y.sati ? (x.order < y.order) : (y.sati < x.sati );
}
bool cmp1(const node &x,const node &y)
{
return x.order > y.order ;
}
int main()
{
int n,m,k ;
double b ;
while(scanf("%d %d %d",&n,&m,&k)!=EOF)
{
for(int i = 0 ; i < m ; i++)
a[i].sati = 0 ;
for(int i = 0 ; i < n ; i++)
{
for(int j = 0 ; j < m ; j++)
{
cin>>b ;
a[j].sati += b ;
a[j].order = j+1 ;
}
}
sort(a,a+m,cmp) ;
sort(a,a+k,cmp1) ;
for(int i = 0 ; i < k-1 ; i++ )
cout<<a[i].order<<" " ;
cout<<a[k-1].order<<endl ;
}
return 0 ;
}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: