以0.01精度在[-100,100]枚举根。
#include<iostream> #include<iomanip> int main() { double a,b,c,d; std::cin>>a>>b>>c>>d; for(double x=-100.0;x<=100.0;x+=0.01) { double f=a*x*x*x+b*x*x+c*x+d; if(f>-0.01&&f<0.01)//因为精度丢失的问题,这里不能写f==0 std::cout<<std::setprecision(2)<<std::fixed<<x<<" "; } }
标签:一元,NOIP2001,求解,double,0.01,100,include From: https://www.cnblogs.com/daigemingzi/p/16610667.html