Advertisement
allia

отжиг

Mar 2nd, 2021 (edited)
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <cstdlib>
  4. using namespace std;
  5.  
  6. double temperature(double i)
  7. {
  8. double temp;
  9. temp = 48/(i);
  10. return temp;
  11. }
  12.  
  13. double trans(double znach_p)
  14. {
  15. int result = 0;
  16. int x_rand = rand()%1;
  17.  
  18. if (x_rand <= znach_p)
  19. result = 1;
  20.  
  21. return result;
  22. }
  23.  
  24. double p(double delta_e, double temperature)
  25. {
  26. double result;
  27. result = exp(-delta_e/temperature);
  28. return result;
  29. }
  30.  
  31. int main()
  32. {
  33. ios_base::sync_with_stdio(false); cin.tie(NULL);
  34. cout.flush();
  35. double znach_pred = 0, znach_next = 0, x_pred = 0, x_next = 50, delta_e = 0, ver = 0, temp = 45;
  36.  
  37. cout.flush() << "? " << x_pred << endl;
  38. cin >> znach_pred;
  39.  
  40. for (int i = 1; i < 50; i++)
  41. {
  42. temp = temperature(i);
  43.  
  44. cout.flush() << "? " << x_next << endl;
  45. cin >> znach_next;
  46.  
  47. delta_e = znach_next - znach_pred;
  48.  
  49. if (delta_e < 0)
  50. znach_next = znach_pred;
  51. else
  52. {
  53. ver = p(delta_e, temp);
  54. if(trans(ver))
  55. {
  56. znach_pred = znach_next;
  57. x_pred = x_next;
  58. }
  59. }
  60. }
  61.  
  62. cout.flush() << "! " << x_next << endl;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement