hust-Ski Race解题报告
英语不好的确害死人,很多人就是因为没看太懂题目意思,所以就卡在这一题了。 所以说作为一个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;
}