为什么答案对的 但是是4个WA
查看原帖
为什么答案对的 但是是4个WA
407175
qq491705331楼主2021/2/10 20:37
#include<iostream>
#include<iomanip>
using namespace std;
int a,b,c,d;
double fun(int x){
	return a*x*x*x+b*x*x+c*x+d; 
}
int main(){
	cin >> a >> b >> c >> d;
	int s=0;
	for(int i=-100; i<100; i++){
		int x1 = i;
		int x2 = i+1;
		double y1 = fun(x1);
		double y2 = fun(x2);
		if(!y1){
			cout << fixed << setprecision(2) << x1 << " ";
			s++;
		}
		if(y1*y2<0){
			while((x1-x2)>0.001){
				int x = (x2-x1)/2;
				if(fun(x)*x2<0){
					x1 = x;
				}
				else if(fun(x)*x1>0){
					x2 = x;
				}
				else{
					cout << fixed << setprecision(2) << x << " ";
					s++;
				}
			} 
		}
		if(s>=3) break;
	}
	cout << endl;
	return 0;
} 

为什么答案对的 但是是4个WA

2021/2/10 20:37
加载中...