Forrest


私信TA

用户名:dotcpp0717441

访问量:1183

签 名:

等  级
排  名 219
经  验 6126
参赛次数 1
文章发表 59
年  龄 0
在职情况 教师
学  校 优学乐程
专  业

  自我简介:

解题思路: 分治。 因为根差的绝对值大于1, 所以以距离为1的区间,依次分治

注意事项:

参考代码:

#include<iostream>
#include<cmath> 
using namespace std;
const double D = 1e-3;
double a, b, c, d;
double check(double x){
	return a * x * x *x + b * x * x + c * x + d ;
}
int main()
{
	cin >> a >> b >> c >> d;
	double l, r ,mid;
	for(int i = -100; i <= 100; i ++){
		l = i, r = i + 1;
		if(check(l) == 0) printf("%.2f ",l);
		else if(check(l) * check(r) < 0){
			while(r - l >= D){
				mid = (l + r) / 2;
				if(check(l) * check(mid) <= 0) r = mid;
				else l = mid;
			}
			printf("%.2f ",mid);
		}
	}
	return 0;
}


 

0.0分

1 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区