HDU 5162 简单排序

来源:互联网 发布:网件的访客网络 编辑:程序博客网 时间:2024/06/15 13:52

Jump and Jump...

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 219    Accepted Submission(s): 161

Problem Description
There are n kids and they want to know who can jump the farthest. For each kid, he can jump three times and the distance he jumps is maximum distance amount all the three jump. For example, if the distance of each jump is (10, 30, 20), then the farthest distance he can jump is 30. Given the distance for each jump of the kids, you should find the rank of each kid.
Input
There are multiple test cases. The first line of input contains an integerT (1T100), indicating the number of test cases. For each test case: The first line contains an integern (2n3), indicating the number of kids. For the next n lines, each line contains three integers ai,bi and ci (1ai,bi,ci,300), indicating the distance for each jump of the i-th kid. It's guaranteed that the final rank of each kid won't be the same (ie. the farthest distance each kid can jump won't be the same).
Output
For each test case, you should output a single line containn integers, separated by one space. The i-th integer indicating the rank of i-th kid.
Sample Input
2310 10 1010 20 3010 10 2023 4 11 2 1
Sample Output
3 1 21 2
Hint
For the first case, the farthest distance each kid can jump is 10, 30 and 20. So the rank is 3, 1, 2.
Source
BestCoder Round #27
////  5162 简单排序.cpp//  HDOJ////  Created by cipher on 15/1/28.//  Copyright (c) 2015年 cipher. All rights reserved.//#include <iostream>#include <stdio.h>#include <algorithm>using namespace std;#define N 305int a[N],b[N];int main(){    int t,i,j,n,max,maxPos,x,k;    scanf("%d",&t);    while (t--) {        scanf("%d",&n);        for (i=0; i<n; i++) {            max=-1;            for (j=0; j<3; j++) {                scanf("%d",&x);                if(max<x){                    max = x;                }            }            a[i]=max;        }        k=1;        for (i=0; i<n; i++)        {            max=a[0];            maxPos=0;            for (j=0; j<n; j++)            {                if(a[j]>max)                {                    max=a[j];                    maxPos=j;                }            }            b[maxPos]=k++;            a[maxPos]=-1;        }        printf("%d",b[0]);        for (i=1; i<n; i++) {            printf(" %d",b[i]);        }        printf("\n");    }    return 0;}
0 0
原创粉丝点击