1.26题目翻译

题目链接:https://acs.jxnu.edu.cn/problem/HDU1227

The fastfood chain McBurger owns several restaurants along a highway. Recently, they have decided to build several depots along the highway, each one located at a restaurant and supplying several of the restaurants with the needed ingredients. Naturally, these depots should be placed so that the average distance between a restaurant and its assigned depot is minimized. You are to write a program that computes the optimal positions and assignments of the depots. 

To make this more precise, the management of McBurger has issued the following specification: You will be given the positions of n restaurants along the highway as n integers d1 < d2 < ... < dn (these are the distances measured from the company's headquarter, which happens to be at the same highway). Furthermore, a number k (k <= n) will be given, the number of depots to be built. 

The k depots will be built at the locations of k different restaurants. Each restaurant will be assigned to the closest depot, from which it will then receive its supplies. To minimize shipping costs, the total distance sum, defined as



must be as small as possible.

Write a program that computes the positions of the k depots, such that the total distance sum is minimized. 

输入:

The input file contains several descriptions of fastfood chains. Each description starts with a line containing the two integers n and k. n and k will satisfy 1 <= n <= 200, 1 <= k <= 30, k <= n. Following this will n lines containing one integer each, giving the positions di of the restaurants, ordered increasingly.

The input file will end with a case starting with n = k = 0. This case should not be processed. 

输出:

For each chain, first output the number of the chain. Then output a line containing the total distance sum. 

Output a blank line after each test case.

快餐连锁店的McBurger在一条高速公路沿线拥有几家餐馆。最近,他们决定在高速公路沿线修建几个仓库,每个仓库都位于一家餐厅里,并供应那些有所需食材的餐馆的几个仓库。当然,这些仓库的放置应该使餐厅和指定仓库之间的平均距离最小化。你要写一个程序 它计算仓库的最佳位置和分配。为了更精确地说,McBurger的管理层已经发布了以下规范:你将得到n个位置 高速公路上的餐厅作为n整数d1d<2<…<dn(这是距离公司总部的距离,恰好在同一条公路上)。此外,一个数字k(k<=n ),将给出要建造的仓库的数量。k个仓库将建在k个不同餐厅的位置。每个餐厅将被分配到最近的仓库,它将从那里开始接收其供应品。为了最小化运输成本,总距离总和,定义为

必须是尽可能的小。编写一个程序来计算k个仓库的位置,从而使总距离和最小化。

输入:

输入文件包含了几种关于快餐连锁店的描述。每个描述以一个包含两个整数n和k的行开始。n和k将满足1<=n<=200,1<=k<=30,k<=n。降低这将n行,每个包含一个整数,给出餐厅的位置,排序越来越多。输入文件将以一个以n=-k=0开头的情况结尾。这种不处理的情况不应该发生。

输出:

对于每个链,首先输出链的编号。然后输出一条包含总距离和的线。在每个测试用例后输出一个空白行。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值