原题
题不难,是个解决套路,详情见代码
#include<iostream>
#include<cstdio>
using namespace std;
double a, b, c, d;
double def(double i){
double y = ((a * i + b) * i + c) * i + d;
return y;
}
int main()
{
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
cin>>a>>b>>c>>d;
for(double i = -100; i <= 100; i ++ ){
double y1 = def(i);
double y2 = def(i + 1);
if(y1 * y2 <= 0){
if(!y1){
printf("%.2f ", i);
}
else if(!y2){
printf("%.2f ", i + 1);
i ++ ;
}
else{
double l = i, r = i + 1, mid;
while(r - l > 1e-3){
mid = l + (r - l) / 2.0;
if(def(l) * def(mid) <= 0) r = mid;
else{
l = mid;
}
}
printf("%.2f ", mid);
}
}
}
return 0;
}