Advertisement
Guest User

Untitled

a guest
Apr 24th, 2016
368
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.10 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. const int MAXN = 100 * 1000 + 5;
  7. const long double EPS = 1e-9;
  8. long double a[MAXN], b[MAXN], p[MAXN], q[MAXN];
  9.  
  10. pair<long double, long double> solve(long double p, long double q) {
  11.     long double d = sqrt(p * p - 4 * q);
  12.     return make_pair((-p + d) / 2, (-p - d) / 2);
  13. }
  14.  
  15. int main() {
  16.     ios_base::sync_with_stdio(false);
  17.     cin.tie(0);
  18.     cout.setf(ios::fixed);
  19.     cout.precision(9);
  20.     int n;
  21.     cin >> n;
  22.     for(int i = 0; i < n; i++)
  23.         cin >> a[i];
  24.     for(int i = 0; i < n; i++)
  25.         cin >> b[i];
  26.     for(int i = 0; i + 1 < n; i++)
  27.         a[i + 1] += a[i];
  28.     for(int i = n - 1; i > 0; i--)
  29.         b[i - 1] += b[i];
  30.     for(int i = 0; i < n; i++) {
  31.         pair<long double, long double> pp = solve(b[i + 1] - a[i] - 1, a[i]);
  32.         p[i] = pp.first;
  33.         q[i] = pp.second;
  34.     }
  35.     for(int i = 0; i < n; i++)
  36.         cout << p[i] - (i? p[i - 1] : 0) << ' ';
  37.     cout << '\n';
  38.     for(int i = 0; i < n; i++)
  39.         cout << q[i] - (i? q[i - 1] : 0) << ' ';
  40.     cout << '\n';
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement