首页 > 其他 > 详细

蚂蚁爬杆

时间:2015-05-10 22:26:39      阅读:349      评论:0      收藏: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;
}
  
}


蚂蚁爬杆

原文:http://blog.csdn.net/wangfengfan1/article/details/45625433

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!