早教吧 育儿知识 作业答案 考试题库 百科 知识分享

英语翻译RanklistSortingYouaregiventhescoresofseveralplayersinacompetition.Yourtaskistocreatearanklistoftheplayers,sortedindecreasingorderbyscore.Unfortunately,thedatastructureusedforthelistofplayerssupportsonlyo

题目详情
英语翻译
Ranklist Sorting
You are given the scores of several players in a competition.Your task is to create a ranklist of the
players,sorted in decreasing order by score.
Unfortunately,the data structure used for the list of players supports only one operation,which
moves a player from position i to position j without changing the relative order of other players.If
i > j,the positions of players at positions between j and i − 1 increase by 1,otherwise if i < j the
positions of players at positions between i + 1 and j decrease by 1.
This operation takes i steps to locate the player to be moved,and j steps to locate the position
where he or she is moved to,so the overall cost of moving a player from position i to position j is
i + j.Here,positions are numbered starting with 1.
Determine a sequence of moves to create the ranklist such that the sum of the costs of the moves is
minimized.
Input
The input is read from a text file named sorting.in .The first line contains n (2
▼优质解答
答案和解析
Ranklist排序
让用户有分数几名球员在竞争.你的任务是创造一个ranklist的
播放器,依次排序的评分.
不幸的是,数据结构用于支持名单的球员只有一个行动,
动作的球员从第一的位置不改变立场j的相对秩序的其他球员.如果
字母i “ J以来,立场球员之间的立场J和我- 1增加1 ,否则,如果我”的j
位置球员之间的立场一+ 1和J减少1 .
此操作步骤,字母i需要找到球员移动,和J步骤定位
他或她是搬到,所以总的成本移动位置的球员从第一的位置J的
一+学者在这里,职位的编号从1 .
确定序列的动作创造ranklist的款项等的费用,此举是
减少到最低限度.
输入
输入读取一个文本文件名为sorting.in .第一行包含ñ ( 2 “为N ” = 1000 ) ,
球员的数量.以下每个ñ行包含一个非负整数硅( 0 “ =市” =
1000000 ) ,得分球员在目前的秩序.你可以假设所有分数是不同的.
输出
输出写入一个文本文件名为sorting.out .第一行中的打印输出
一些动作用于创建ranklist .以下几行应指定动作的
为了在被应用.每个移动应予以说明的行包含两个整数字母i
和J ,这意味着球员的位置移动到第一的位置学者数字I和J必须
分隔的一个空间.
例如
sorting.in sorting.out
分级
30 %的测试案例有价值观的N “ = 10