Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <cstdlib>.
  4. #include <iomanip>
  5. #include <regex>
  6. #include <math.h>
  7. #include <ctime>
  8. #include <random>
  9. using namespace std;
  10.  
  11. double fRand(double fMin, double fMax)
  12. {
  13. double f = (double)rand() / RAND_MAX;
  14. return fMin + f * (fMax - fMin);
  15. }
  16.  
  17. int main() {
  18. double x0, x1, ans, y1, bestx, besty, newp, t = 10000, p, eps = 0.0000000001;
  19. cout.flush();
  20. cout.precision(7);
  21. cout.setf(ios::fixed);
  22. bestx = fRand(-100, 100);
  23. cout << "? " << bestx << endl;
  24. cin >> besty;
  25. while (t > eps) {
  26. x1 = bestx + fRand(-25, 25);
  27. cout << "? " << x1 << endl;
  28. cin >> y1;
  29. if (y1 < besty) {
  30. besty = y1;
  31. bestx = x1;
  32. }
  33. else {
  34. p = exp(-(y1 - besty) / t);
  35. newp = fRand(0, 1);
  36. if (newp <= p) {
  37. besty = y1;
  38. bestx = x1;
  39. }
  40. }
  41. t *= 0.99;
  42. }
  43. cout << "! " << bestx << endl;
  44. return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement