zoukankan      html  css  js  c++  java
  • 穿越沙漠 FZU

    题意:

      一辆吉普车来到 (x) 公里宽的沙漠边沿 (A) 点,吉普车的耗油量为 (1) 升/公里,总装油量为 (500) 升。通常,吉普车必须用自身油箱中的油在沙漠中设置若干个临时储油点,才能穿越沙漠的。假设在沙漠边沿 (A) 点有充足的汽油可供使用,那么吉普车从 (A) 点穿过这片沙漠到达终点 (B),至少要耗多少升油。请编写一个程序,计算最少的耗油量(精确到小数点后 (3) 位)。
    (1)假设吉普车在沙漠中行进时不发生故障;
    (2)吉普车在沙漠边沿A点到终点B的直线距离为 (xgeq 500) 公里(即沙漠宽度);

    分析:

    逆向递推。

    代码:

    #include <cstdio>
    using namespace std;
    int main()
    {
        int t,k;
        scanf("%d",&t);
        while(t--)
        {
            double dis=0,oil=0,x;//距离起点的距离
            scanf("%lf",&x);
            k=0;
            while(dis<x)
            {
                k++;
                dis+=(500.0/(2*k-1));
                oil=500.0*k;
                //cout<<"dis= "<<dis<<" oil="<<oil<<endl;
            }
            if(dis>x)//把多走的部分减掉
                oil-=(dis-x)*(2*k-1);
            printf("%.3f
    ",oil);
        }
        return 0;
    }
    
    
  • 相关阅读:
    Red and Black POJ
    Catch That Cow HDU
    Lotus and Horticulture HDU
    进击的绿色
    北京办护照
    女码农真诚征gg
    bitset
    long long
    cnblogs latex公式
    2050 Programming Competition (CCPC)
  • 原文地址:https://www.cnblogs.com/1024-xzx/p/12696288.html
Copyright © 2011-2022 走看看