Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const long double EPS = 1e-2;
- int n;
- pair<bool, long double> check(long double m, long double prev) {
- long double tec = m;
- bool ok = (tec > 0);
- for(int i = 2; i < n; ++i) {
- long double c = 2.0 + 2.0 * tec - prev;
- if(!(c > 0)) {
- return {false, tec};
- }
- prev = tec;
- tec = c;
- }
- return {ok, tec};
- }
- int32_t main()
- {
- //freopen("garland.in", "r", stdin);
- //freopen("garland.out", "w", stdout);
- long double x;
- cin >> n >> x;
- long double l = 0, r = x, ans = 0;
- for (int i = 0; i < 50; ++i) {
- long double m = (l + r) / 2.0;
- auto checked = check(m , x);
- if(checked.first) {
- r = m;
- ans = checked.second;
- }
- else
- l = m;
- }
- cout.precision(10);
- cout << fixed << ans << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement