You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
705 B

2 years ago
#include <bits/stdc++.h>
using namespace std;
// 例4、穿越沙漠
// https://blog.csdn.net/weixin_43983838/article/details/88125782
int main() {
int dis = 500, oil = 500;
int k = 1;
//因为不确定循环次数又至少做一次所以我们用do_while
do {
printf("储油点%d距离出发点%5d,", k, 1000 - dis);
printf("储油量%5dL\n", oil);
k = k + 1;
dis = dis + 500 / (2 * k - 1);
oil = 500 * k;
} while (dis < 1000);
// 再计算出发点的储油量
oil = 500 * (k - 1) + (1000 - dis) * (2 * k - 1);
printf("储油点%d距离出发点%5d,储油量%5dL\n", k, 0, oil);
return 0;
}