题目传送门:https://www.luogu.com.cn/problem/P3382
模板:
1 #include<iostream>
2 #include<cstdio>
3 #include<algorithm>
4 #include<vector>
5 #include<map>
6 #include<queue>
7 #include<set>
8 #include<cmath>
9 #include<list>
10 #include<cstring>
11 #include<string>
12 #define ll long long
13 #define ull unsigned long long
14 #define inf 0x3f3f3f3f
15 #define inff 0x7fffffff
16 using namespace std;
17 const int N = 100000 + 10;
18
19 int n;
20 double a[N];
21
22 double f(double x) {
23 double ans = 0;
24 for (int i = 0; i <= n; i++) {
25 ans += (pow(x, i) * a[i]);
26 }
27 return ans;
28 }
29
30 int main() {
31
32 //int n;
33 cin >> n;
34 double l, r;
35 cin >> l >> r;
36 for (int i = n; i >= 0; i--) {
37 cin >> a[i];
38 }
39 double midl, midr, ans;
40 while (fabs(r - l) > 1e-15) {
41 midl = (l + r) / 2;
42 midr = (midl + r) / 2;
43 if (f(midl) < f(midr)) {
44 l = midl;
45 }
46 else {
47 r = midr;
48 }
49 //cout << l << "\n";
50 }
51 cout << l << "\n";
52
53 return 0;
54 }