Advertisement
bibaboba12345

бп по ответу для владимира петровича

Sep 24th, 2021
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <random>
  4. #include <vector>
  5. #include <deque>
  6. #include <algorithm>
  7. #include <random>
  8. #include <cmath>
  9. #include <iomanip>
  10. using namespace std;
  11. long double eps = 1e-6, L, R;
  12. long long t,n,fst,snd,trd;
  13.  
  14. long double fun(long double x) {
  15. return cos(x) - x;
  16. }
  17.  
  18. long double bp(long double l, long double r) {
  19. if (r - l <= eps) {
  20. return l;
  21. }
  22. long double mid = (l + r) / 2;
  23. if (fun(mid) > 0) {
  24. return bp(l, mid);
  25. }
  26. else {
  27. return bp(mid, r);
  28. }
  29. }
  30. long double bp_r(long double l, long double r) {
  31.  
  32. if (r - l <= eps) {
  33. return l;
  34. }
  35. long double mid = (l + r) / 2;
  36. if (fun(mid) < 0) {
  37. return bp_r(l, mid);
  38. }
  39. else {
  40. return bp_r(mid, r);
  41. }
  42. }
  43.  
  44. int main()
  45. {
  46. cin >> eps >> L >> R;
  47. cout << fixed << setprecision(10);
  48. if (fun(L) <= 0) {
  49. cout << bp(L, R);
  50. }
  51. else {
  52. cout << bp_r(L, R);
  53. }
  54. return 0;
  55. }
  56.  
  57.  
  58.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement