编程介的小学生 2019-04-19 12:00 采纳率: 20.5%
浏览 133

如何排列让差异最小的算法的解决,运用C语言的程序编写的技巧如何才能实现

Problem Description
Recently, Kiki are asked to arrange a competition. Before the competition, everyone have an expectation of the ranking. To make all the players happy , Kiki wants to minimize the sum of all the players’ difference. We define the difference of a player as |ai-bi|, ai stands for one’s expected ranking ,and bi stands for one’s final ranking.

Input
There are several test cases.
Each case begins with an integer n ,(n<= 100)stands for the number of players in this competition.
Then follows n lines ,each line contains a string s and an integer m,(the string will contains no more than 20 characters and no space in it, 1<=m<=n) stands for the name of the player and his expected ranking.

Output
The output contains one line for each data set : the minimum sum of differences Kiki can get.

Sample Input
7
a 1
b 2
c 2
d 1
e 5
g 7
f 7

Sample Output
5

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 求差集那个函数有问题,有无佬可以解决
    • ¥15 【提问】基于Invest的水源涵养
    • ¥20 微信网友居然可以通过vx号找到我绑的手机号
    • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
    • ¥15 解riccati方程组
    • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
    • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
    • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
    • ¥50 树莓派安卓APK系统签名
    • ¥65 汇编语言除法溢出问题