LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 2084|回复: 24

趣味编程:bicycle problem

[复制链接]
发表于 2003-10-1 00:36:06 | 显示全部楼层 |阅读模式
Puzzle:
A boy, a girl and a dog go for a 10 mile walk. The boy and girl can walk at 2 mph and the dog can trot at 4 mph. They also have a bicycle which only one of them (including the dog!) can use at a time. When riding, the boy and girl can travel at 12 mph while the dog can pedal(踩脚踏)at 16 mph. What is the shortest time in which all three can complete the trip?

Please give your solution ,thread or code etc.

感觉程序设计版不够热闹,贴些有意思的东西,来活跃活跃气氛
发表于 2003-10-1 09:17:20 | 显示全部楼层
这里还不够热闹啊?呵呵,题目挺有趣的。
想想啊…………
发表于 2003-10-1 12:44:50 | 显示全部楼层
谢谢

我想这应该先列出公式 然后开始求解

置顶看看大家的算法
 楼主| 发表于 2003-10-1 13:39:04 | 显示全部楼层
大家有空多参与。此题可以扩充到其它更复杂的情况。
发表于 2003-10-1 14:01:59 | 显示全部楼层
对我来说太难了,还是看看大家怎么做的,再来学习。
单纯当数学题做,我都没做出来。
发表于 2003-10-2 08:49:03 | 显示全部楼层
我的思路是:完成的时间取决于最慢那一个完成全程所用的时间,由于男孩和女孩的速度相同,所以应该保证他们用自行车的时间相同。狗由于速度最快,所以不能让它闲着,也即是最好不要让它先到终点在那里浪费时间(浪费资源)。正确的答案我现在也想不出来。
发表于 2003-10-2 13:32:41 | 显示全部楼层
按照float的思路,the boy and the girl各在其一半路程上骑车,所需时间tb=tg=5/12+5/2, 虽然the dog没有骑车,但当the boy and the girl到达终点时,the dog已经在那里休息了25分钟了。

  1. int main ()
  2. {
  3.    double length=10;
  4.    double tb, td;
  5.    tb=length/2/12+length/2/2;
  6.    td=length/4;
  7.    if (tb>td)
  8.       cout<<"The shortest time is "<<tb<<" hours."<<endl;
  9.    else
  10.       cout<<"Unfortunately"<<td<<endl;
  11. }
复制代码


 楼主| 发表于 2003-10-2 15:06:51 | 显示全部楼层
给点提示,并不一定非要沿一个方向。
发表于 2003-10-2 18:57:35 | 显示全部楼层
那只狗应该可以折回来:可能的情况就是男孩或女孩的某一个人先骑车一段距离,然后开始步行,狗碰到车的时候骑回来给那个慢的(不一定要与那个慢的碰头),放下车后狗继续赶路。

不知道思路对不对。
 楼主| 发表于 2003-10-2 22:00:20 | 显示全部楼层
讲的很对。想想看还漏了点什么。
他们分别到达目的地所用的时间上有何关系?
然后就可以动手编了。:)
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表