Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define int long long
- #define TASKNAME "garland"
- using namespace std;
- typedef long double ld;
- const int N = 1e5 + 7, ITER = 100;
- ld h[N];
- ld ans = 0;
- bool can(int n, ld h1, ld x) {
- ld prev = h1, cur = x;
- bool res = (cur > 0);
- for(int i = 2; i < n; i ++)
- {
- ld next = cur * 2.0 - prev + 2.0;
- if(!(next > 0))
- {
- res = 0;
- break;
- }
- prev = cur, cur = next;
- }
- if(res)
- ans = cur;
- return res;
- }
- int32_t main() {
- srand(time(NULL));
- freopen(TASKNAME".in", "r", stdin);
- freopen(TASKNAME".out", "w", stdout);
- int n;ld h1;
- cin >> n >> h1;
- ld l = 0, r = h1;
- int it = 0;
- while(it < ITER)
- {
- it ++;
- ld m = (l + r) / 2;
- if(can(n, h1, m))
- r = m;
- else
- l = m;
- }
- cout << fixed << ans << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement