HDU 1031(服装打分 **)

题意是有 n 个人要对 m 件服装打分,按总分从高到低排序,再将总分排在前 k 名的服装按编号的从高到低输出,结构体排序。

代码如下:

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 struct shirt
 4 {
 5     int num;
 6     double price;
 7 }t[1000];
 8 bool cmp1(shirt a,shirt b)
 9 {
10     return a.price>b.price;
11 }
12 bool cmp2(shirt a,shirt b)
13 {
14     return a.num>b.num;
15 }
16 int main()
17 {
18     int n,m,k;
19     double tmp;
20     while(~scanf("%d%d%d",&n,&m,&k))
21     {
22         for(int i = 0; i < m; ++i)
23         {
24             t[i].price = 0;
25             t[i].num = i+1;
26         }
27         for(int i = 0; i < n; ++i)
28             for(int j = 0; j < m; ++j)
29             {
30                 scanf("%lf",&tmp);
31                 t[j].price += tmp;
32             }
33         sort(t,t+m,cmp1);
34         sort(t,t+k,cmp2);
35         for(int i = 0; i < k-1; ++i)
36             printf("%d ",t[i].num);
37         printf("%d
",t[k-1].num);
38     }
39     return 0;
40 }
View Code
日后若能有更好的想法,再来完善。 希望看到的大神不吝赐教 orz
原文地址:https://www.cnblogs.com/Taskr212/p/9550807.html