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……- -找了半天问题。。