7 条题解

  • 4
    @ 2023-4-1 8:41:08

    $\texttt{\large\color{#12a1e8}本\color{#50ce50}蒟蒻\color{#12a1e8}的第\color{#c291e8}七\color{#12a1e8}篇\color{#92a1e8}题\color{#92a9d8}解}$

    手动开3次方{\large\color{#92a1e8}手动开3次方}

    难度:入门\texttt{\small\color{#e51211}难度:入门}

    last update:2023/4/1


    pow()可以求一个数的多次方(通用于c++和python),是常用函数,然后输出的时候取两位即可


    Python{\large\color{#52a1e8}Python:}

    a=int(input())
    result=float(pow(a,1/3))
    #round(result,2)
    print('%.2f'%result)
    

    C++{\large\color{#52a1e8}C++:}

    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
     float n,y;
     scanf("%f",&n);
     y=(float)pow (n,1.0/3);
     printf("%.2f\n",y);
     return 0;
    }
    
    • 2
      @ 2025-3-3 12:36:36
      a=int(input())
      b=float(pow(a,1/3))
      print('%.2f'%b)
      
      • 0
        @ 2025-5-6 15:54:19

        #include #include // 用于比较误差 using namespace std;

        // 计算x的三次方根的函数,使用牛顿迭代法 double cbrt(double x, double tolerance) { if (x == 0) { return 0; }

        double guess = x / 3; // 初始猜测值
        double next_guess;
        
        do {
            next_guess = (2 * guess + x / (guess * guess)) / 3; // 牛顿迭代公式
            if (abs(next_guess - guess) < tolerance) { // 如果误差小于容忍度,则停止迭代
                return next_guess;
            }
            guess = next_guess;
        } while (true);
        

        }

        int main() { double x; cout << "Enter a number to calculate its cube root: "; cin >> x;

        double tolerance = 1e-10; // 设置误差容忍度
        double result = cbrt(x, tolerance);
        
        if (result != -1) {
        
            cout << "The cube root of " << x << " is approximately " << result << endl;
            cout << "Standard library result: " << cbrt(x) << endl; // 使用标准库函数进行比较
        }
        
        return 0;
        

        }

        • 0
          @ 2025-3-13 13:12:15
          a=int(input())
          print("%.2f" %(a**(1/3)))
          
          
          • 0
            @ 2022-8-2 19:18:42

            cmath库实现

            #include <bits/stdc++.h>
            using namespace std;
            int main()
            {
                double n;
                cin >> n;
                printf("%.2lf",pow(n,1.0/3));
                return 0;
            }
            

            二分查找

            #include <bits/stdc++.h>
            using namespace std;
            int main() 
            {
                double n;
                cin >> n;
                double l = -10000, r = 10000;
                while (r - l >= 1e-8) {
                    double mid = (r + l) / 2;
                    if (mid * mid * mid >= n) r = mid;
                    else l = mid;
                }
                printf("%.2lf", l);
            }
            
            • 0
              @ 2022-7-9 16:17:19
              #include<bits/stdc++.h>
              using namespace std;
              int main()
              {
              	double n,b;
              	cin>>n;
              	b=pow(n,1.0/3);
              	printf("%.2lf",b);
              
              • -1
                @ 2023-7-16 18:18:08

                枚举

                #include <iostream>
                using namespace std;
                int n;
                int main(){
                    cin>>n;
                    for (double i=1;i<=500;i=i+0.0001){
                        if((n-i*i*i)<0.0001){
                            printf("%.2f",i);
                            break;
                        }
                    }
                    return 0;
                }
                

                c++

                • 1

                信息

                ID
                51
                时间
                1000ms
                内存
                128MiB
                难度
                1
                标签
                递交数
                393
                已通过
                259
                上传者