找回密码
 立即注册
搜索
总共850条微博

动态微博

查看: 2695|回复: 5
打印 上一主题 下一主题
收起左侧

瓶子体积比较

[复制链接]

456

主题

1770

帖子

2万

积分

跳转到指定楼层
楼主
发表于 2005-3-5 03:51:48 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

有5个形状不同,体积不同的瓶子。比较两个瓶子体积的唯一办法是将一个瓶子装满水,倒入另一个。当然,如果a>b,b>c,那么不用比a和c也知道a大。
现在要找出体积第3的那个瓶子,最坏情况需要比较几次?怎么比?
www.ddhw.com

 
回复

使用道具 举报

9

主题

77

帖子

795

积分

沙发
发表于 2005-3-5 08:54:40 | 只看该作者

回复:瓶子体积比较[>:D<]


这个是不是等同于数据结构里的有5个数,用最坏的冒泡法(Bubble Sort)比较大小并排序的最坏的效率呢?
是不是n(n-1)/2次?也就是10次?(我认为的前提是如果5个顺序不排定,就没法找出第三个,可能我认为的这个前提也有误)
www.ddhw.com

 
回复 支持 反对

使用道具 举报

1

主题

19

帖子

151

积分

板凳
发表于 2005-3-5 09:26:27 | 只看该作者

显然不需要十次


先四个排序,最多6 次,设次序为A>B>C>D. 现在让剩下的E 和B 比较,如果E>B, 那么选B; 如果Ewww.ddhw.com
回复 支持 反对

使用道具 举报

5

主题

155

帖子

1115

积分

地板
发表于 2005-3-5 11:24:50 | 只看该作者

Seven times is enough.


Four comparisons to decide the largest one and the smallest one  among four bottles, which sure can not be the answer. Then three comparisons to decide the middle one among the remaining three bottles. www.ddhw.com
 
Do not know if it is the best.
www.ddhw.com

 
回复 支持 反对

使用道具 举报

5

主题

155

帖子

1115

积分

5#
发表于 2005-3-5 12:01:24 | 只看该作者

Six.


Deleting the smallest one among four bottles is a waste.
Three comparison to decide the largest one among four bottles.
(Compare A and B, then compare C and D; wlog, assume A>B, C>D, compare A and C, assume A>C)


Ignoring the largest one A, we are left
B, E  and C>D.
Compare B and E, assume that B>E; compare B and C, assume that B>C. Compare E and C, the larger one is the 3rd among five bottles. (Six times. )

We did not compare the 4th and 5th. So seven times is enough to sort the list witht 5 members.

www.ddhw.com

 

回复 支持 反对

使用道具 举报

5

主题

155

帖子

1115

积分

6#
发表于 2005-3-5 13:12:18 | 只看该作者

The last sentence is wrong


  The last sentence is wrong




回复 支持 反对

使用道具 举报

24小时热帖
    一周热门
      原创摄影
        美食美文
          您需要登录后才可以回帖 登录 | 立即注册

          本版积分规则

          Archiver|手机版|珍珠湾ART

          Powered by Discuz! X3 © 2001-2013 All Rights Reserved