BestCoder27 1001.Jump and Jump... (hdu 5162) 解题报告

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

题目意思:有 n 个 kid,每个 kid 有三个成绩 a, b, c。选最大的一个成绩作为这个 kid 的最终成绩。然后根据每个 kid 的最终成绩,对他们进行排名。

     赛中写得比较丑陋,这个还比较顺眼。。。。呵呵

   

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstdlib>
 4 #include <cstring>
 5 #include <algorithm>
 6 using namespace std;
 7 
 8 const int maxn = 5 + 2;
 9 struct node
10 {
11     int id;
12     int score;
13     bool operator < (const node &a) const {
14         return score > a.score;
15     }
16 }kid[maxn];
17 int ans[maxn];
18 
19 int main()
20 {
21    int t, n, in;
22    while (scanf("%d", &t) != EOF) {
23        while (t--) {
24            memset(ans, 0, sizeof(ans));
25            scanf("%d", &n);
26            for (int i = 0; i < n; i++) {
27                int maxx = -1;
28                for (int j = 0; j < 3; j++) {
29                    scanf("%d", &in);
30                    maxx = max(maxx, in);
31                }
32                kid[i].id = i+1;
33                kid[i].score = maxx;
34            }
35            sort(kid, kid+n);
36            for (int i = 0; i < n; i++)
37                 ans[kid[i].id] = i+1;
38            for (int i = 1; i <= n; i++)
39                 printf("%d%c", ans[i], i == n ? '\n' : ' ');
40        }
41    }
42    return 0;
43 }

 

  

posted @ 2015-01-25 12:53  windysai  阅读(328)  评论(0)    收藏  举报