布豪,死循环
查看原帖
布豪,死循环
1024366
LCA_楼主2024/12/19 20:30
#include <bits/stdc++.h>
using namespace std;
int a, b, c, d;

int f(int x) {
	return (a * pow(x, 3) + b * pow(x, 2) + c * x + d);
}

int main() {
	cin >> a >> b >> c >> d;
	int x1, x2;
	for (int x = -100; x <= 100; x++) {
		x1 = x, x2 = x + 1;
		if (f(x1) == 0) {
			printf("%.2f", x1);
		} else if (f(x1)*f(x2) < 0) {
			while (x2 - x1 >= 0.001) {
				int xx = (x2 + x1) / 2;
				if (f(x1)*f(xx) <= 0) {
					x2 = xx;
				} else {
					x1 = xx;
				}
			}
			printf("%.2f", x1);
		}
	}
	return 0;
}
2024/12/19 20:30
加载中...