Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. #include <vector>
  2. #include <algorithm>
  3. #include <iomanip>
  4. #include <math.h>
  5. #include <fstream>
  6.  
  7. using namespace std;
  8.  
  9. double bin_search(double begin, double end, int n, double a)
  10. {
  11. double middle = begin + (end - begin) / 2;
  12. vector <double> arr = { a, middle };
  13. for (int i = 2; i < n; ++i)
  14. arr.push_back(2 * (1 + arr.at(i - 1)) - arr.at(i - 2));
  15.  
  16. if (end - begin > 0.000000000001)
  17. if (*min_element(arr.begin(), arr.end()) >= 0)
  18. return bin_search(begin, middle, n, a);
  19. else
  20. return bin_search(middle, end, n, a);
  21.  
  22. return arr.at(arr.size() - 1);
  23. }
  24. int main()
  25. {
  26. ifstream ist("garland.in");
  27. ofstream ost("garland.out");
  28.  
  29. int n; // [3 : 1000]
  30. double A; // [10 : 1000.0]
  31. ist >> n >> A;
  32.  
  33. double B = abs(bin_search(0, 1000, n, A));
  34. ost << fixed << setprecision(2) << B;
  35.  
  36. return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement