This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
#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;
}