题解
2024-07-25 16:30:36
发布于:浙江
7阅读
0回复
0点赞
#include <bits/stdc++.h>
using namespace std;
double a, b, c, d;
double check(double x) {
return a * x * x * x + b * x * x + c * x + d;
}
int main() {
cin >> a >> b >> c >> d;
for (double i = -100; i < 100; i++) {
double j = i + 1;
if (check(i) == 0)
cout<<fixed<<setprecision(2)<<i<<" ";
if (check(j)*check(i) < 0) {
double l = i;
double r = j;
while (r - l > 0.00001) {
double mid = (l + r) / 2.0;
if (check(l)*check(mid) < 0)
r = mid;
else
l = mid;
}
cout<<fixed<<setprecision(2)<<l<<" ";
}
}
return 0;
}
30行
全部评论 1
写错了,是27行
2024-07-25 来自 浙江
0
有帮助,赞一个