Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <cmath>
- #include <ctime>
- #include <cstdlib>
- #include <map>
- using namespace std;
- const int n = 1000, m = 1000;
- dx[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
- dy[8] = {1, 1, 1, 0, -1, -1, -1, 0};
- double sqr(double a) {
- return a * a;
- }
- double f(const pair<int, int> &coord) {
- double x = coord.first / 500, y = coord.second / 500;
- return exp(-sqr(x - 1) - sqr(y - 1));
- // return exp(- x * x - y * y) * (sin(100 * x * x) + 1) * (-cos(100 * y * y) + 1);
- // return exp(-5*sqr(x-0.2)-5*sqr(y-0.5))+exp(-sqr(x-2)-sqr(y))+exp(-5*sqr(x-1.3)-5*sqr(y-0.8))+exp(-5*sqr(x-1.5)-5*sqr(y-0.1));
- }
- double eval_time_point(const pair<int, int> &coord) {
- return f(coord);
- }
- bool check(const vector<pair<int, int> > &path) {
- if (path[0].first != 0 || path[0].second != 0 ||
- path[path.size() - 1].first != n || path[path.size() - 1].second != m) {
- return false;
- }
- for (int i = 0; i < path.size() - 1; ++i) {
- if (abs(path[i].first - path[i + 1].first) > 1 ||
- abs(path[i].second - path[i + 1].second) > 1) {
- return false;
- }
- }
- return true;
- }
- double eval_time_path(const vector < pair<int, int> > &path) {
- if (!check(path)) {
- return -1;
- }
- double time = 0;
- for (auto &coord: path) {
- time += f(coord);
- }
- return time;
- }
- vector < pair<int, int> > generate_path() {
- vector < pair<int, int> > best_path;
- double best_time = 1E+9;
- for (int i = 0; i < 5; ++i){
- vector < pair<int, int> > path;
- pair<int, int> current_coord(0, 0);
- path.push_back(current_coord);
- map <int, pair<int, int> > max_coords;
- map <int, pair<int, int> > n_points;
- for(int i = 0; i < 8; i++){
- current_coord.first = current_coord.first+dx[i];
- current_coord.second = current_coord.second+dy[i];
- max_coords.insert( eval_time_point(current_coord), make_pair(current_coord.first, current_coord.second));
- n_point[time] = make_pair();
- }
- if (eval_time_path(path) < best_time) {
- best_time = eval_time_path(path);
- best_path = path;
- }
- }
- return best_path;
- }
- int main() {
- cout << eval_time_path(generate_path()) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement