From 338fd50ccadcbcc3a6ce7441b77da7623d5d78cb Mon Sep 17 00:00:00 2001 From: Ren Baoshuo Date: Sun, 20 Dec 2020 09:07:48 +0800 Subject: [PATCH] =?UTF-8?q?P3382=20=E3=80=90=E6=A8=A1=E6=9D=BF=E3=80=91?= =?UTF-8?q?=E4=B8=89=E5=88=86=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit R43941020 --- problem/P3382/P3382.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 problem/P3382/P3382.cpp diff --git a/problem/P3382/P3382.cpp b/problem/P3382/P3382.cpp new file mode 100644 index 00000000..f8821546 --- /dev/null +++ b/problem/P3382/P3382.cpp @@ -0,0 +1,34 @@ +#include + +using namespace std; + +const double eps = 1e-11; +int n; +double l, r, a[20], mid1, mid2; + +double f(double x) { + double s = 0; + for (int i = n; i >= 0; i--) { + s = s * x + a[i]; + } + return s; +} + +int main() { + cin >> n >> l >> r; + for (int i = n; i >= 0; i--) { + cin >> a[i]; + } + while (r - l >= eps) { + mid1 = l + (r - l) / 3.0; + mid2 = r - (r - l) / 3.0; + if (f(mid1) > f(mid2)) { + r = mid2; + } + else { + l = mid1; + } + } + cout << fixed << setprecision(5) << l << endl; + return 0; +}