Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <random>
- #include <vector>
- #include <deque>
- #include <algorithm>
- #include <random>
- #include <cmath>
- #include <iomanip>
- using namespace std;
- long double eps = 1e-6, L, R;
- long long t,n,fst,snd,trd;
- long double fun(long double x) {
- return cos(x) - x;
- }
- long double bp(long double l, long double r) {
- if (r - l <= eps) {
- return l;
- }
- long double mid = (l + r) / 2;
- if (fun(mid) > 0) {
- return bp(l, mid);
- }
- else {
- return bp(mid, r);
- }
- }
- long double bp_r(long double l, long double r) {
- if (r - l <= eps) {
- return l;
- }
- long double mid = (l + r) / 2;
- if (fun(mid) < 0) {
- return bp_r(l, mid);
- }
- else {
- return bp_r(mid, r);
- }
- }
- int main()
- {
- cin >> eps >> L >> R;
- cout << fixed << setprecision(10);
- if (fun(L) <= 0) {
- cout << bp(L, R);
- }
- else {
- cout << bp_r(L, R);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement