You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
856 B
35 lines
856 B
#include <bits/stdc++.h>
|
|
//P1204
|
|
using namespace std;
|
|
double a, b, c, d;
|
|
|
|
double f(double x) {
|
|
return a * x * x * x + b * x * x + c * x + d;//方程部分
|
|
}
|
|
|
|
int main() {
|
|
int i;
|
|
double x, y, mid;
|
|
cin >> a >> b >> c >> d;
|
|
for (i = -100; i <= 100; i++)//循环,枚举查找
|
|
{
|
|
x = i;
|
|
y = x + 1;//两个指针
|
|
if (f(x) == 0) {
|
|
printf("%.2f", x);
|
|
cout << " ";
|
|
}//如果符合条件则直接输出
|
|
else if (f(x) * f(y) < 0)//如果其中有解就开始二分
|
|
{
|
|
while (y - x >= 0.001)//精度要求
|
|
{
|
|
mid = (x + y) / 2;
|
|
if (f(mid) * f(x) <= 0)y = mid;//判断解在哪个区间
|
|
else x = mid;
|
|
}
|
|
printf("%.2f", x);
|
|
cout << " ";
|
|
}
|
|
}
|
|
return 0;
|
|
} |