Files
python/TangDou/DiTui/ChuanYueShaMo.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

23 lines
705 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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;
}