求助,为什么本地能过,提交全WA
查看原帖
求助,为什么本地能过,提交全WA
593189
muxiuyulin0913楼主2023/1/30 17:07
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
long double a, b, c,d;
long double f(long double x) {
	return a * x * x * x + b * x * x + c * x + d;
}
long double Calculator(long double low, long double high){
	long double middle = (low + high) / 2;
	if (abs(low - high) <= 0.0001) return middle;
	if (f(low) * f(middle) < 0) return Calculator(low, middle);
	else return Calculator(middle, high);
}
int main()
{
	cin >> a >> b>>c>>d;
	long double L1, L2;
	L1 = (-2 * b - sqrt(4 * b * b - 4 * 3 * a * c)) / (2 * 3 * a);
	L2 = (-2 * b + sqrt(4 * b * b - 4 * 3 * a * c)) / (2 * 3 * a);
	long double tmp1, tmp2, tmp3;
	tmp1 = Calculator(-100, L1);
	tmp2 = Calculator(L1, L2);
	tmp3 = Calculator(L2, 100);
	printf("%.2lf ", tmp1);
	printf("%.2lf ", tmp2);
	printf("%.2lf ", tmp3);
	return 0;
}

2023/1/30 17:07
加载中...