Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <cstdlib>.
- #include <iomanip>
- #include <regex>
- #include <math.h>
- #include <ctime>
- #include <random>
- using namespace std;
- double fRand(double fMin, double fMax)
- {
- double f = (double)rand() / RAND_MAX;
- return fMin + f * (fMax - fMin);
- }
- int main() {
- double x0, x1, ans, y1, bestx, besty, newp, t = 10000, p, eps = 0.0000000001;
- cout.flush();
- cout.precision(7);
- cout.setf(ios::fixed);
- bestx = fRand(-100, 100);
- cout << "? " << bestx << endl;
- cin >> besty;
- while (t > eps) {
- x1 = bestx + fRand(-25, 25);
- cout << "? " << x1 << endl;
- cin >> y1;
- if (y1 < besty) {
- besty = y1;
- bestx = x1;
- }
- else {
- p = exp(-(y1 - besty) / t);
- newp = fRand(0, 1);
- if (newp <= p) {
- besty = y1;
- bestx = x1;
- }
- }
- t *= 0.99;
- }
- cout << "! " << bestx << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement