題目:http://www.luogu.org/problem/show?pid=1024#
分析:二分
代碼:
#include <cstdio>
#include <algorithm>
using namespace std;
double a,b,c,d;
double f(double x)
{
return a*x*x*x+b*x*x+c*x+d;
}
void work(double l,double r)
{
double mid;
while(r-l>=)
{
mid=l+(r-l)/;
if(f(mid)<&&f(mid)>-) {
printf("%.2lf ",mid);
return;
}
if(f(l)*f(mid)<=) r=mid;
else l=mid;
}
return;
}
int main()
{
scanf("%lf %lf %lf %lf",&a,&b,&c,&d);
for(double i=-;i<=;i+=)
if(f(i)*f(i+)<=)
{
work(i,i+);
i+=;
}
return ;
}