Advertisement
Guest User

Untitled

a guest
Jun 24th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.35 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <cmath>
  4. #include <ctime>
  5. #include <cstdlib>
  6. #include <map>
  7.  
  8. using namespace std;
  9.  
  10. const int n = 1000, m = 1000;
  11.  
  12. dx[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
  13. dy[8] = {1, 1, 1, 0, -1, -1, -1, 0};
  14.  
  15. double sqr(double a) {
  16.     return a * a;
  17. }
  18.  
  19. double f(const pair<int, int> &coord) {
  20.     double x = coord.first / 500, y = coord.second / 500;
  21.     return exp(-sqr(x - 1) - sqr(y - 1));
  22.     // return exp(- x * x - y * y) * (sin(100 * x * x) + 1) * (-cos(100 * y * y) + 1);
  23.     // 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));
  24. }
  25.  
  26. double eval_time_point(const pair<int, int> &coord) {
  27.     return f(coord);
  28. }
  29.  
  30. bool check(const vector<pair<int, int> > &path) {
  31.     if (path[0].first != 0 || path[0].second != 0 ||
  32.         path[path.size() - 1].first != n || path[path.size() - 1].second != m) {
  33.         return false;
  34.     }
  35.  
  36.     for (int i = 0; i < path.size() - 1; ++i) {
  37.         if (abs(path[i].first - path[i + 1].first) > 1 ||
  38.             abs(path[i].second - path[i + 1].second) > 1) {
  39.             return false;
  40.         }
  41.     }
  42.  
  43.     return true;
  44. }
  45.  
  46. double eval_time_path(const vector < pair<int, int> > &path) {
  47.     if (!check(path)) {
  48.         return -1;
  49.     }
  50.     double time = 0;
  51.     for (auto &coord: path) {
  52.         time += f(coord);
  53.     }
  54.     return time;
  55. }
  56.  
  57. vector < pair<int, int> > generate_path() {
  58.  
  59.     vector < pair<int, int> > best_path;
  60.     double best_time = 1E+9;
  61.  
  62.     for (int i = 0; i < 5; ++i){
  63.         vector < pair<int, int> > path;
  64.         pair<int, int> current_coord(0, 0);
  65.  
  66.         path.push_back(current_coord);
  67.         map <int, pair<int, int> > max_coords;
  68.         map <int, pair<int, int> > n_points;
  69.         for(int i = 0; i < 8; i++){
  70.             current_coord.first = current_coord.first+dx[i];
  71.             current_coord.second = current_coord.second+dy[i];
  72.             max_coords.insert( eval_time_point(current_coord), make_pair(current_coord.first, current_coord.second));
  73.  
  74.             n_point[time] = make_pair();
  75.         }
  76.  
  77.         if (eval_time_path(path) < best_time) {
  78.             best_time = eval_time_path(path);
  79.             best_path = path;
  80.         }
  81.     }
  82.  
  83.     return best_path;
  84. }
  85.  
  86. int main() {
  87.     cout << eval_time_path(generate_path()) << endl;
  88.     return 0;
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement