|
以文本方式查看主题 - 计算机科学论坛 (http://bbs.xml.org.cn/index.asp) -- 『 算法理论与分析 』 (http://bbs.xml.org.cn/list.asp?boardid=60) ---- 一道C语言题 (http://bbs.xml.org.cn/dispbbs.asp?boardid=60&rootid=&id=56670) |
|
-- 作者:hitlyq -- 发布时间:12/12/2007 5:50:00 PM -- 一道C语言题 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD><TITLE>Problem 1005 - Fast Food</TITLE> <META http-equiv=Content-Type content="text/html; charset=utf-8"><LINK href="http://acm.hit.edu.cn/ojs/ojs.css" type=text/css rel=stylesheet><LINK href="http://acm.hit.edu.cn/ojs/prob.css" type=text/css rel=stylesheet> <META content="MSHTML 6.00.6000.16544" name=GENERATOR></HEAD> <BODY> <CENTER><A href="http://acm.hit.edu.cn/OJS"><IMG src="http://acm.hit.edu.cn/ojs/pic/banner.gif" border=0></A> </CENTER><FONT color=red></FONT> <CENTER class=heading>Fast Food</CENTER> <HR> <CENTER> <CENTER> </PRE></TD></TR></TBODY></TABLE> <CENTER class=default><A <CENTER class=default>Copyright © 1998-2006, HIT ACM/ICPC Group<BR>All Rights |
|
-- 作者:guoleihit -- 发布时间:1/15/2008 5:21:00 PM -- 【原帖】 Fast Food -------------------------------------------------------------------------------- Time limit: 3sec. Submitted: 863 Source : Unknown -------------------------------------------------------------------------------- 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 Write a program that computes the positions of the k depots, such that the total distance sum is minimized. Input 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. Output 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. Sample Input 6 3 Sample Output Chain 1 |
|
-- 作者:yangzhj05 -- 发布时间:4/25/2008 5:36:00 PM -- 算法:每次选取相隔距离最大的两个点,则标记那两个点,然后递归操作,直至达到k值结束 |
|
W 3 C h i n a ( since 2003 ) 旗 下 站 点 苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》 |
6,457.031ms |