7 条题解

  • 4
    @ 2023-8-4 21:46:52
    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
        double a,b,c,d,x;
        cin>>x>>a>>b>>c>>d;
        double t=a*x*x*x+b*x*x+c*x+d;
        cout<<fixed<<setprecision(7)<<t<<endl;
        return 0;
    }
    

    🔶注意要精确到小数点后7位哦

    • 3
      @ 2023-5-20 3:40:05

      解析:

      多项式f(x)=ax3+bx2+cx+df(x) = ax^3+bx^2+cx+d可以写成f(x)=axxx+bxx+cx+df(x) = a*x*x*x+b*x*x+c*x+d

      所以按照题目要求输入x,a,b,c,dx, a, b, c, d就能求出结果。

      参考代码:

      #include <iostream>
      #include <iomanip>
      using namespace std;
      int main()
      {
          double a, b, c, d, x;
          cin >> x >> a >> b >> c >> d;
          cout << fixed << setprecision(7) << a * x * x * x + b * x * x + c * x + d;
          return 0;
      }
      
      • 2
        @ 2023-8-9 20:01:04

        题目描述

        对于多项式f(x) = ax^3+bx^2+cx+d和给定的a,b,c,d,x,计算f(x)的值,保留到小数点后7位。 输入1行:x,a,b,c,d(都是绝对值不超过100的双精度浮点数)

        注意事项

        1. 式子:axxx+bxx+cx+d

        AC代码

        #include <bits/stdc++.h> 
        using namespace std;
        double a,b,c,d,x;
        int main()
        {
            cin >> x >> a >> b >> c >> d;
            cout << fixed << setprecision(7) << a*x*x*x+b*x*x+c*x+d;
            return 0;
        }
        
        
        • 1
          @ 2023-5-21 15:35:26

          【解题思路】

          根据上面的公式,我们可以得出f(x) = a * x * x * x + b * x * x + c * x + d,所以只要定义f,a,b,c,d,x然后直接套公式,输出即可。 代码:

          #include<iostream>
           
          #include<bits/stdc++.h>
           
          using namespace std;
           
          int main()
          {
          	double x, a, b, c, d, f;
          	
          	cin >> x >> a >> b >> c >> d;
          	
          	f = 1.0 * a * x * x * x + b * x * x + c * x + d;
           
          	cout.setf(ios::fixed);
           
          	cout.precision(7);
           
          	
          	cout << f << endl;
          	
          	return 0;
           
          }
          
          
          
          
          • 0
            @ 2024-5-2 16:23:49
            #include <iostream>
            #include <cstdio>//导库
            using namespace std;
            int main()
            {
            double x,a,b,c,d,ans;//定义5个实数,ans用来存储答案
            cin >> x >> a >> b >> c >> d;
            ans = a*x*x*x+b*x*x+c*x+d;
            printf("%.7f",ans);//使用格式化输出保留7位小数,也可使用setprecsion
            return 0;
            }
            ```
            
            • 0
              @ 2024-4-12 11:52:19
              #include <iostream>
              #include <cstdio>
              #include <cmath>
              #include <iomanip>
              using namespace std;
              int main(){
                  double x,a,b,c,d;
                  scanf("%lf %lf %lf %lf %lf",&x,&a,&b,&c,&d);
                  double e=a*pow(x,3)+b*pow(x,2)+c*x+d;
                  printf("%.7f",e);
                  return 0;
              }
              
              • 0
                @ 2024-3-3 14:57:55
                #include <bits/stdc++.h>
                using namespace std;
                int main()
                {
                    double a, b, c, d, x, f = 0;
                    cin >> x >> a >> b >> c >> d;
                    f = a * x * x * x + b * x * x + c * x + d;
                    cout << fixed << setprecision(7) << f;
                    return 0;
                }
                
                • 1

                信息

                ID
                83
                时间
                1000ms
                内存
                128MiB
                难度
                2
                标签
                递交数
                411
                已通过
                242
                上传者