2,4超时!?求助
查看原帖
2,4超时!?求助
778465
sweet_sweet楼主2023/10/22 19:08
#include<bits/stdc++.h>
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(){
	double x1,x2,l,r,m;
	cin>>a>>b>>c>>d;
	for(int i=-100;i<=100;i++){
		x1=i,x2=i+1;
		if(f(x1)==0)
		cout<<fixed<<setprecision(2)<<x1<<" "; 
		else if(f(x1)*f(x2)<0){
			l=x1,r=x2;
			while(r-1>=1e-3)
			{
				m=(l+r)/2;
				if(f(m)*f(1)>0)
				l=m;
				else if(f(m)*f(1)<0)
				r=m;
				else
				break;
			}
			cout<<fixed<<setprecision(2)<<m<<" ";
		}
			
	}
	
	return 0;
} 
2023/10/22 19:08
加载中...