7 条题解
-
2
题目描述
对于多项式f(x) = ax^3+bx^2+cx+d和给定的a,b,c,d,x,计算f(x)的值,保留到小数点后7位。 输入1行:x,a,b,c,d(都是绝对值不超过100的双精度浮点数)
注意事项
- 式子: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
【解题思路】
根据上面的公式,我们可以得出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; }
- 1
信息
- ID
- 83
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 2
- 标签
- 递交数
- 411
- 已通过
- 242
- 上传者