hust-Ski Race解题报告

hust-Ski Race解题报告

Description

Now you are asked for help by the organizers of the Winter Olympic Games 2014, which, as you know, will be held in Yekaterinozavodsk. And although there are still 5 and a half years ahead, the first sport facility is already put into operation. It is the track for the ski race.
Although the track has modern and reliable equipment, the organizers want to know what to do in case it fails. For instance, what will happen if the stopwatch on the finish breaks down and only the relative order of the sportsmen is known? The rules of the ski race make things even worse: the participants start the race one after another, with a 30 seconds delay, and therefore the sportsman who finishes first doesn't have to be the first in the ranklist. For example, if the sportsman who started second would finish 25 second after the sportsman who started first, it would mean that he passed the track 5 seconds faster than his rival and therefore should be placed higher in the final ranklist.
You are to write a program that will determine for each sportsman the highest and the lowest place he can possibly have in the final ranklist, given the relative order in which the sportsmen finished the race.

Input

The first line contains an integer  n — the number of the race participants  (1 ≤  n ≤ 2000) . The participants are numbered from 1 to  naccording to the order they started the race. The second line contains a permutation of numbers from 1 to  n — the order in which the skiers finished.

Output

Output  n lines;  i-th line should contain a pair of space-separated integers — the lowest and the highest possible place in the final ranklist for  i-th race participant.

Sample Input

input output
6
3 5 1 4 2 6
3 6
4 6
1 4
2 5
1 3
1 6


英语不好的确害死人,很多人就是因为没看太懂题目意思,所以就卡在这一题了。 所以说作为一个acmer英语一定要好(有点自嘲的感觉....)

题目大意:

在这个特殊的滑雪比赛中,有n个参赛队员,从1~n分别是这几个参赛队员的编号,而且也是他们的出发的顺序。1号队员先出发,后面依次出发。输入数据的第二行是代表队员到达终点的顺序,例如上面的输入样例3 5 1 4 2 6,代表3号是第一个到达终点,5号是第二个,1号是第一个......以此类推。输出的意思是,第一行表示1号参赛队员的rank,第一个数字代表1号队员的最佳的成绩排名,第二个数字表示1号队员的最差排名.....后面几行同理。

解题思路:

通过分析可以发现,其实这个题目只要分析出来队员的两个状态,就容易推出来最终的可能排名。一个是比该队员先行后到的人数有多少,设为P,二是比该队员后行先到的人数有多少,设为Q。最好的排名就是Q+1,最差的排名就是n-P


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int final[2011];//到达终点的顺序
int rank1[2011],rank2[2011];//最佳排名与最差排名
int main()
{
    int numren;//总参赛人数
    while(scanf("%d",&numren)!=EOF)
    {
        int i,j,k;
        for(i=0;i<numren;i++)
            scanf("%d",&final[i]);
        int temp;
        int flag1[2011],flag2[2011];//flag1记录先行后到的情况,flag2记录后行先到的情况
        memset(flag1,0,sizeof(flag1));
        memset(flag2,0,sizeof(flag2));
        for(i=0;i<numren;i++)
        {
                for(k=0;k<numren;k++)
                    if(final[k]-1==i)
                    {
                        temp=k;break;//temp用于标记目标队员到达终点的位置
                    }
                for(j=0;j<numren;j++)
                {
                    if(final[j]-1<i&&j>temp)//先行后到的人
                        flag1[i]++;         //记录这种情况的人数
                    if(final[j]-1>i&&j<temp)//后行先到的人
                        flag2[i]++;         //记录这种情况的人数
                }
        }
        for(i=0;i<numren;i++)
        {
            rank1[i]=flag2[i]+1;
            rank2[i]=numren-flag1[i];
        }
        for(i=0;i<numren;i++)
        {
            printf("%d %d\n",rank1[i],rank2[i]);
        }
    }
    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值