Current location - Education and Training Encyclopedia - Graduation thesis - Programming: A Difficult Algorithm Problem ................
Programming: A Difficult Algorithm Problem ................
//crossing the desert problem

/*

Use jeep to cross 1000 km desert.

The total fuel consumption of the jeep is 500 gallons, and the fuel consumption rate is 1 gallon/km.

Since there is no oil depot in the desert, we should first use this car to build a temporary oil depot in the desert.

Jeeps cross the desert with the least fuel consumption, where to build oil depots, and the oil storage capacity of each place.

*/

# include & ltstdio.h & gt

# include & ltiostream & gt

Use namespace std

Void Desert ()

{

int dis,k,oil,d 1;

dis = 500

k = 1;

Oil = 500;

Cout & lt& lt "No. Starting oil storage (km) "< <; endl

Do {

cout & lt& ltk & lt& lt" " " & lt& lt 1000-dis & lt; & lt" ""<& lt petroleum & lt& ltendl

k = k+ 1;

d 1 = dis;

dis = dis+500/(2 * k- 1);

Oil = 500 * k;;

} while(dis & lt; 1000);

cout & lt& ltendl

//origin oil storage

Oil = 500 * (k-1)+(1000-dis) * (2 * k-1);

Cout & lt<k<< ""<<0< ""<< oil<& ltendl.

}

int main(int argc,char *argv[])

{

Desert ();

Returns 0;

}