跳到正文

个人记录

111111

five_rice_water约 1 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月15日
篇幅
约 1 分钟

版本

  1. v1当前
C++
#include <bits/stdc++.h>
using namespace std;
const int N = 15;
const double eps = 1e-9;
int n;
double a[N];
double l, r;

double check(double x) {
	double res = 0;
	for (int i = 1; i <= n + 1; i++) {
		res *= x;
		res += a[i];
	}
	return res;
}

int main() {
	cin >> n >> l >> r;
	for (int i = 1; i <= n + 1; i++) {
		cin >> a[i];
	}
	while (r - l > eps) {
		double mid1 = l + (r - l) / 3.0;
		double mid2 = r - (r - l) / 3.0;
		if (check(mid1) < check(mid2)) {
			l = mid1;
		} else {
			r = mid2;
		}
	}
	cout << fixed << setprecision(5) << l << endl;
	return 0;
}
原文