Bestcoder 27 # A jump and jump

本文介绍了一种通过三次跳跃成绩确定每位参赛者最远距离,并据此进行排名的算法实现。适用于2到3位参赛者的小型比赛场景。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值