package algorithm;
public class test {
public static void main(String args[]) {
int stationCount = method();
System.out.println("途中共有油站"+stationCount+"个");
for(int i=1;i<=stationCount;i++){
float s=0;
int k=1;
while(k<=stationCount+1-i){
s+=500.0/(2*(k++)-1);
}
float oil=500*(stationCount+1-i);
//System.out.println("nihao");
System.out.println("第"+i+"个储油点: "+"距离终点"+s+" "+"油量"+oil);
}
}
public static int method() {
float s = 0;
for (int m = 1;; m++) {
s += 500.0/ (2 * m - 1);
if (s >= 1000) {
s -= 500.0/ (2 * m - 1);
double oil=3500.0+(double)(1000-s)*15;
//System.out.println(s);
System.out.println("穿越沙漠的总耗油量"+oil);
return m - 1;// 去除起点
}
}
}
}
穿越沙漠问题
猜你喜欢
转载自blog.csdn.net/qq_36728361/article/details/83188892
今日推荐
周排行