版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/QingCoffe/article/details/85099637
这题模拟就好了....一直模拟u d 到出坑,看结果..当然最简单的还是找规律...用公式来计算...有点烦..懒得找了直接模拟AC了
# include<iostream>
using namespace std;
int main(void) {
int n, u, d;
int time , distance;
cin >> n >> u >> d;
while (n || u || d) {
time = distance = 0;
while(++time) {
if (time & 1) {//奇数跑
distance += u;
}
else {//偶数落
distance -= d;
continue;
}
if (distance >= n)break;//模拟出结果
}
cout << time << endl;//结果
cin >> n >> u >> d;//下一次循环
}
system("pause");
return 0;
}