Advertisement
Infiniti_Inter

Перебор

Oct 7th, 2020 (edited)
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include<iostream>
  3. #include<string>
  4. #include<alg.h>
  5.  
  6. using namespace std;
  7. const double EPS = 1e-4;
  8. const int INF = 1e8 + 13;
  9.  
  10.  
  11.  
  12. double func(double x)
  13. {
  14. return 2. * x*x - 6 * x - 3;
  15. }
  16.  
  17. pair<double, double> solve()
  18. {
  19.  
  20. double left = -1;
  21. double right = 3;
  22. double step = 0.00001;
  23. double answer = INF;
  24. double answerPoint = -INF;
  25. for (double x = left; left <= right; x += step)
  26. {
  27. double cur = func(x);
  28. if (answer == INF)
  29. {
  30. answer = cur;
  31. continue;
  32. }
  33. if (cur <= answer)
  34. {
  35. answer = cur;
  36. answerPoint = x;
  37. }
  38. else
  39. break;
  40. }
  41. return { answer, answerPoint };
  42. }
  43.  
  44. int main()
  45. {
  46. freopen("input.txt", "r", stdin);
  47. freopen("output.txt", "w", stdout);
  48.  
  49. pair<double, double> ans = solve();
  50. cout << "min = " << ans.first << "\nwith x = " << ans.second << endl;
  51.  
  52. }
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement