Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <vector>
- #include <algorithm>
- #include <iomanip>
- #include <math.h>
- #include <fstream>
- using namespace std;
- double bin_search(double begin, double end, int n, double a)
- {
- double middle = begin + (end - begin) / 2;
- vector <double> arr = { a, middle };
- for (int i = 2; i < n; ++i)
- arr.push_back(2 * (1 + arr.at(i - 1)) - arr.at(i - 2));
- if (end - begin > 0.000000000001)
- if (*min_element(arr.begin(), arr.end()) >= 0)
- return bin_search(begin, middle, n, a);
- else
- return bin_search(middle, end, n, a);
- return arr.at(arr.size() - 1);
- }
- int main()
- {
- ifstream ist("garland.in");
- ofstream ost("garland.out");
- int n; // [3 : 1000]
- double A; // [10 : 1000.0]
- ist >> n >> A;
- double B = abs(bin_search(0, 1000, n, A));
- ost << fixed << setprecision(2) << B;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement