编程介的小学生 2019-05-29 19:53 采纳率: 20.5%
浏览 109

差异最小化的实现的算法,怎么才能采用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 kafka 分区副本增加会导致消息丢失或者不可用吗?
    • ¥15 微信公众号自制会员卡没有收款渠道啊
    • ¥15 stable diffusion
    • ¥100 Jenkins自动化部署—悬赏100元
    • ¥15 关于#python#的问题:求帮写python代码
    • ¥20 MATLAB画图图形出现上下震荡的线条
    • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
    • ¥15 perl MISA分析p3_in脚本出错
    • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
    • ¥15 ubuntu虚拟机打包apk错误