Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const long double EPS = 1e-2;
  4. int n;
  5. pair<bool, long double> check(long double m, long double prev) {
  6. long double tec = m;
  7. bool ok = (tec > 0);
  8. for(int i = 2; i < n; ++i) {
  9. long double c = 2.0 + 2.0 * tec - prev;
  10. if(!(c > 0)) {
  11. return {false, tec};
  12. }
  13. prev = tec;
  14. tec = c;
  15. }
  16. return {ok, tec};
  17. }
  18.  
  19. int32_t main()
  20. {
  21.  
  22. //freopen("garland.in", "r", stdin);
  23. //freopen("garland.out", "w", stdout);
  24.  
  25. long double x;
  26. cin >> n >> x;
  27. long double l = 0, r = x, ans = 0;
  28. for (int i = 0; i < 50; ++i) {
  29. long double m = (l + r) / 2.0;
  30. auto checked = check(m , x);
  31. if(checked.first) {
  32. r = m;
  33. ans = checked.second;
  34. }
  35. else
  36. l = m;
  37. }
  38. cout.precision(10);
  39. cout << fixed << ans << endl;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement