现在的位置: 首页 > 综合 > 正文

Bestcoder 27 # A jump and jump

2018年04月28日 ⁄ 综合 ⁄ 共 1749字 ⁄ 字号 评论关闭

Jump and Jump...

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


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 integer T (1T100),
indicating the number of test cases. For each test case: The first line contains an integer n (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 contain n integers,
separated by one space. The i-th
integer indicating the rank of i-th
kid.
 


Sample Input
2 3 10 10 10 10 20 30 10 10 20 2 3 4 1 1 2 1
 


Sample Output
3 1 2 1 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.

代码:

# include<cstdio>
# include<iostream>
# include<algorithm>

using namespace std;

# define MAX 5

struct node
{
    int id;
    int jump;
    int rk;
}b[MAX];

int a[MAX];

int cmp( const struct node & x,const struct node & y )
{
    return x.jump>y.jump;
}

int cmp2( const struct node & x,const struct node & y )
{
    return x.id < y.id;
}


int main(void)
{
    int t;cin>>t;
    while ( t-- )
    {
        int n;cin>>n;
        int j = 1;
        for ( int t = 1;t <= n;t++ )
        {
            for ( int i = 1;i <= 3;i++ )
                    {
                        cin>>a[i];
                    }
            sort(a+1,a+1+3);
            b[j++].jump = a[3];
            //j++;
        }
    for ( int i = 1;i <= n;i++ )
    {
        b[i].id = i;
    }
        sort(b+1,b+1+n,cmp);
        for ( int i = 1;i <= n;i++ )
        {
            b[i].rk = i;
        }
        sort(b+1,b+1+n,cmp2);
        for ( int i = 1;i <= n-1;i++ )
        {
            cout<<b[i].rk<<" ";
        }
        cout<<b[n].rk<<endl;
        //cout<<endl;



    }


    return 0;
}

抱歉!评论已关闭.