6 条题解

  • 3
    @ 2024-3-24 15:26:19
    #include <bits/stdc++.h>
    #include<cmath>
    using namespace std;
    int main()
    {
        double s;
        cin>>s;
        int step=0;
        double tance=0.0;
        while (tance<s) {
            step++;
            tance +=2*pow(0.98,step-1);
        }
        cout<<step<<endl;
        return 0;
    }
    //程序首先读入距离是,使用while循环,计算小玉的步数。在每一次循环中,增加步数step,并根据上一步的距离计算出这一步的距离2*pow(0.98,step-1)。我们使用pow计算幂,因为每一步是上一步的0.98倍。如果小玉游的总距离tance还没有达到s,就继续循环。当tance大于等于s时,就跳出循环并输出步数step。
    

    信息

    ID
    653
    时间
    1000ms
    内存
    125MiB
    难度
    4
    标签
    (无)
    递交数
    218
    已通过
    100
    上传者