# Untitled

a guest
Apr 24th, 2016
149
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #include <bits/stdc++.h>
2.
3. using namespace std;
4.
5. const int MAXN = 500000;
6. double Pref[MAXN], Suff[MAXN];
7. double PA[MAXN], PB[MAXN];
8.
10. double a = PA[i] - PA[i - 1];
11. double b = PB[i] - PB[i - 1];
12.
13. double rez = Pref[i - 1] + a * PB[i - 1] + b * PA[i - 1] + a * b;
14. if(fabs(rez - Pref[i]) < 1e-9)
15. return false;
16. return true;
17. }
18.
19. void getSols(int i) {
20. double prod = Pref[i];
21. double b = Suff[i + 1];
22.
23. //b = 1 - (sum) + (prod)
24. double sum = 1 - b + prod;
25.
26. //Stim suma si produsul -> profit
27. double disc = sqrt(fabs(sum * sum - 4 * prod));
28. PA[i] = (sum + disc) / 2;
29. PB[i] = (sum - disc) / 2;
30.
32. }
33.
34. int main() {
35. int n;
36. cin >> n;
37.
38. for(int i = 1; i <= n; ++i) {
39. cin >> Pref[i];
40. Pref[i] += Pref[i - 1];
41. }
42. for(int i = 1; i <= n; ++i) {
43. cin >> Suff[i];
44. }
45. for(int i = n; i >= 1; --i) {
46. Suff[i] += Suff[i + 1];
47. }
48.
49. for(int i = 1; i <= n; ++i) {
50. getSols(i);
51. }
52.
53. cout << fixed << setprecision(12);
54. for(int i = 1; i <= n; ++i) {
55. cout << PA[i] - PA[i - 1] << " ";
56. }
57. cout << endl;
58. for(int i = 1; i <= n; ++i) {
59. cout << PB[i] - PB[i - 1] << " ";
60. }
61. cout << endl;
62.
63. return 0;
64. }
RAW Paste Data