chillurbrain

Доп. из 10.2. Простые вычисления

May 26th, 2016
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include<iostream>
  2. #include<cmath>
  3. using namespace std;
  4. int N;
  5. const double eps = 1e-9;
  6. double a[3010], c[3010], x;
  7. void solve()
  8. {
  9.     for (int i = 2; i <= N; i++)a[i] = 2 * (a[i - 1] + c[i - 1]) - a[i - 2];
  10.     x = 2 * (a[N] + c[N]) - a[N - 1];
  11. }
  12. int main()
  13. {
  14.     scanf("%d", &N);
  15.     scanf("%lf%lf", &a[0], &a[N + 1]);
  16.     for (int i = 1; i <= N; i++)cin >> c[i];
  17.     double l = -2000.000, r = 2000.00;
  18.     while (l - r<eps)
  19.     {
  20.         double mid = (l + r) / 2.0;
  21.         a[1] = mid;
  22.         solve();
  23.         if (fabs(a[N + 1] - x)<eps){ printf("%.2lf\n", mid); break; }
  24.         else if (a[N + 1] - x<eps)r = mid; else l = mid;
  25.     }
  26.     return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment