新书推介:《语义网技术体系》
作者:瞿裕忠,胡伟,程龚
   XML论坛     W3CHINA.ORG讨论区     计算机科学论坛     SOAChina论坛     Blog     开放翻译计划     新浪微博  
 
  • 首页
  • 登录
  • 注册
  • 软件下载
  • 资料下载
  • 核心成员
  • 帮助
  •   Add to Google

    >> We choose to study algorithmic problems,  not because they are easy,  but because they are hard.
    [返回] 计算机科学论坛计算机理论与工程『 算法理论与分析 』 → 一道C语言题 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 6786 个阅读者浏览上一篇主题  刷新本主题   树形显示贴子 浏览下一篇主题
     * 贴子主题: 一道C语言题 举报  打印  推荐  IE收藏夹 
       本主题类别:     
     hitlyq 帅哥哟,离线,有人找我吗?
      
      
      等级:大一新生
      文章:2
      积分:58
      门派:XML.ORG.CN
      注册:2007/12/12

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给hitlyq发送一个短消息 把hitlyq加入好友 查看hitlyq的个人资料 搜索hitlyq在『 算法理论与分析 』的所有贴子 引用回复这个贴子 回复这个贴子 查看hitlyq的博客楼主
    发贴心情 一道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>
    <TABLE class=default border=0>
      <TBODY>
      <TR>
        <TD align=right>Time limit:</TD>
        <TD width=50>3sec.</TD>
        <TD align=right>Submitted:</TD>
        <TD width=50>863</TD></TR>
      <TR>
        <TD align=right>Memory limit:</TD>
        <TD width=50>32M</TD>
        <TD align=right>Accepted:</TD>
        <TD width=50>208</TD></TR></TBODY></TABLE></CENTER>
    <CENTER>Source : <A
    href="http://acm.hit.edu.cn/ojs/result.php?str=%22Unknown%22"><FONT
    color=red>Unknown</FONT></A></CENTER>
    <HR>

    <CENTER>
    <TABLE class=default cellSpacing=10 cellPadding=10 width="100%" border=0>
      <TBODY>
      <TR vAlign=top>
        <TD>
          <P>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.</P>
          <P>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 &lt; d2 &lt; ... &lt; dn (these are the
          distances measured from the company's headquarter, which happens to be at
          the same highway). Furthermore, a number k (k &lt;= n) will be given, the
          number of depots to be built. </P>
          <P>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</P>
          <CENTER><IMG src="http://acm.hit.edu.cn/ojs/pic/1005_a.gif"></CENTER>
          <P>must be as small as possible.</P>
          <P>Write a program that computes the positions of the k depots, such that
          the total distance sum is minimized. </P><B>Input</B><BR>
          <P>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 &lt;= n &lt;= 200, 1 &lt;= k &lt;= 30, k &lt;= n.
          Following this will n lines containing one integer each, giving the
          positions di of the restaurants, ordered increasingly.</P>
          <P>The input file will end with a case starting with n = k = 0. This case
          should not be processed. </P><B>Output</B><BR>
          <P>For each chain, first output the number of the chain. Then output a
          line containing the total distance sum. </P>
          <P>Output a blank line after each test case. </P><B>Sample Input </B><BR><PRE>6 3
    5
    6
    12
    19
    20
    27
    0 0
    </PRE><B>Sample Output</B><BR><PRE>Chain 1
    Total distance sum = 8

    </PRE></TD></TR></TBODY></TABLE>
    <HR>

    <CENTER class=default><A
    href="http://acm.hit.edu.cn/ojs/status.php?Proid=1005&amp;Contestid=0">Status</A>&nbsp;&nbsp;
    <A
    href="http://acm.hit.edu.cn/OJS/Submit?Proid=1005&amp;Contestid=0">Submit</A>&nbsp;&nbsp;
    <A
    href="http://acm.hit.edu.cn/ojs/answer.php?Proid=1005">Solution</A>&nbsp;&nbsp;
    <A href="http://acm.hit.edu.cn/forum/viewforum.php?f=11"><FONT
    color=red>Discuss</FONT></A> </CENTER>
    <HR>

    <CENTER class=default>Copyright &copy; 1998-2006, HIT ACM/ICPC Group<BR>All Rights
    Reserved </CENTER></CENTER></BODY></HTML>


       收藏   分享  
    顶(0)
      




    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2007/12/12 17:50:00
     
     guoleihit 帅哥哟,离线,有人找我吗?
      
      
      等级:大一(猛啃高等数学)
      文章:14
      积分:104
      门派:XML.ORG.CN
      注册:2008/1/4

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给guoleihit发送一个短消息 把guoleihit加入好友 查看guoleihit的个人资料 搜索guoleihit在『 算法理论与分析 』的所有贴子 引用回复这个贴子 回复这个贴子 查看guoleihit的博客2
    发贴心情 
    【原帖】
    Fast Food

    --------------------------------------------------------------------------------

    Time limit: 3sec. Submitted: 863
    Memory limit: 32M Accepted: 208

    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


    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.

    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
    5
    6
    12
    19
    20
    27
    0 0

    Sample Output

    Chain 1
    Total distance sum = 8

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2008/1/15 17:21:00
     
     yangzhj05 帅哥哟,离线,有人找我吗?
      
      
      等级:大一新生
      文章:9
      积分:87
      门派:Lilybbs.net
      注册:2008/4/22

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给yangzhj05发送一个短消息 把yangzhj05加入好友 查看yangzhj05的个人资料 搜索yangzhj05在『 算法理论与分析 』的所有贴子 引用回复这个贴子 回复这个贴子 查看yangzhj05的博客3
    发贴心情 
    算法:每次选取相隔距离最大的两个点,则标记那两个点,然后递归操作,直至达到k值结束

    ----------------------------------------------
    多读代码->多读好代码->多读Linux源码

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2008/4/25 17:36:00
     
     GoogleAdSense
      
      
      等级:大一新生
      文章:1
      积分:50
      门派:无门无派
      院校:未填写
      注册:2007-01-01
    给Google AdSense发送一个短消息 把Google AdSense加入好友 查看Google AdSense的个人资料 搜索Google AdSense在『 算法理论与分析 』的所有贴子 访问Google AdSense的主页 引用回复这个贴子 回复这个贴子 查看Google AdSense的博客广告
    2024/11/30 10:21:24

    本主题贴数3,分页: [1]

    管理选项修改tag | 锁定 | 解锁 | 提升 | 删除 | 移动 | 固顶 | 总固顶 | 奖励 | 惩罚 | 发布公告
    W3C Contributing Supporter! W 3 C h i n a ( since 2003 ) 旗 下 站 点
    苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
    82.031ms