穿越沙漠问题:

穿越沙漠问题:一辆吉普车穿越1000km的沙漠。吉普车的总装油量为500加仑,耗油率
为1加仑每千米。由于沙漠中没有油库。若吉普车用最少的耗油量穿越沙漠,应在哪些地

方建立油库,以及各处存储的油量?


#include
int main()
{
    int dis, k, oil,i;
    int distances[10], oilquantities[10];
    dis = 500; k = 1; oil = 500;
    do
    {
        distances[k] = 1000 - dis;//距离起点的距离
        oilquantities[k] = 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);
    distances[k] = 0;
    oilquantities[k] = oil;
    for (i = k; i>=1; i--)
    {
        printf("storepoint: %d,  distance: %d, oilquantity: %d\n", k+1-i, distances[i],oilquantities[i]);
    }
    return 0;
}

你可能感兴趣的:(算法设计与分析)