蚂蚁爬杆
来源:互联网 发布:凡高网络 编辑:程序博客网 时间:2024/06/11 19:37
问题:
解答:
伪代码如下:
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 0
- 蚂蚁爬杆问题
- 蚂蚁爬杆
- 蚂蚁爬杆
- 蚂蚁爬杆
- java蚂蚁爬杆
- 蚂蚁爬杆
- bjtuOJ1137 蚂蚁爬杆
- 蚂蚁爬杆问题
- 蚂蚁爬杆问题
- 蚂蚁爬杆
- 蚂蚁爬杆问题
- 蚂蚁爬杆+uva10881
- 蚂蚁爬杆
- 蚂蚁爬杆
- 蚂蚁爬杆问题
- 蚂蚁爬杆问题
- 蚂蚁爬杆问题
- 4.7 蚂蚁爬杆
- python中的坑
- Future异常
- 【机房重构】—模板方法+存储过程简单实现组合查询
- 9--黑马程序员--技术总结之多线程
- ios7实现语音朗读功能
- 蚂蚁爬杆
- hdu 1159 最长公共字串
- C/C++中各种类型int、long long、double表示范围(最大最小值)
- java环境搭建
- android学习课程的知识结构
- 10--黑马程序员--技术总结之异常
- 利用注册表实现程序开机启动
- ios开发极易犯的错误
- kali apt-get update失败解决方法