poj1852 Ants 穷竭搜索

An army of ants walk on a horizontal pole of length l cm, each with a constant speed of 1 cm/s. When a walking ant reaches an end of the pole, it immediatelly falls off it. When two ants meet they turn back and start walking in opposite directions. We know the original positions of ants on the pole, unfortunately, we do not know the directions in which the ants are walking. Your task is to compute the earliest and the latest possible times needed for all ants to fall off the pole.

题意:讲的是n个蚂蚁在一个长度为L的竿子上爬行。当蚂蚁爬到竿子终点的时候就会掉落。两只蚂蚁相遇的时候只能各自反爬回去,求问所有蚂蚁下落竿子的最短时间和最长时间。

题解:可以假设蚂蚁是可以相遇的。这样不管蚂蚁的方向都可以走到尾。我们用现在蚂蚁离竿尾的长度为K,那么另一头竿尾的长度为L-K。用穷竭搜索就可以找到最短和最长的时间。PS:之前用c++的cin和cout输入输出流,一直都是TLE……- -找了半天问题。。

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值