蚂蚁爬杆

论坛 期权论坛 编程之家     
选择匿名的用户   2021-6-2 20:54   1452   0

问题:

解答:




伪代码如下:

void CalcTime(double Length,// length of the stick
double *XPos,//position of an ant,<=length
int AntNum, //number of ants
double Speed, //speed of ants
double &Min,//return value of the minimum time
double &Max)//return value of the maximum time
{
//parameter checking ,Omitted
//total time needed for traveling the whole stick
double TotalTime = Length / Speed;
Max = Min = 0;
for (int i = 0; i < AntNum; i++)
{
double currentMax = 0;
double currentMin = 0;
if (XPos[i]>(Length / 2))
currentMax = XPos[i] / Speed;
else
currentMax = (Length - XPos[i]) / Speed;
currentMin = TotalTime - Max;
if (Max < currentMax)
Max = currentMax;
if (Min < currentMin)
Min = currentMin;
}

}


分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP