Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.09 KB | None | 0 0
  1. void timer(int** Map)
  2. {
  3.     vector<pair<int, int> > wave;
  4.     vector<pair<int, int> > oldWave;
  5.     oldWave.push_back(pair<int, int>(1, 1));
  6.     int nstep = 0;
  7.     map[1][1] = nstep;
  8.     const int dx[] = { 0, 1, 0, -1 };
  9.     const int dy[] = { -1, 0, 1, 0 };
  10.     while (oldWave.size() > 0)
  11.     {
  12.         ++nstep;
  13.         wave.clear();
  14.         for (vector<pair<int, int> >::iterator i = oldWave.begin(); i != oldWave.end(); ++i)
  15.         {
  16.             for (int d = 0; d < 4; ++d)
  17.             {
  18.                 int nx = i->first + dx[d];
  19.                 int ny = i->second + dy[d];
  20.                 if (map[nx][ny] == -1)
  21.                 {
  22.                     wave.push_back(pair<int, int>(nx, ny));
  23.                     map[nx][ny] = nstep;
  24.                     if (nx == N - 2 && ny == N - 2)
  25.                         goto done;
  26.                     for (int b = 0; b < 10000; ++b)
  27.                     {
  28.                     }
  29.                 }
  30.             }
  31.         }
  32.         oldWave = wave;
  33.     }
  34. done:
  35.     int x = N - 2;
  36.     int y = N - 2;
  37.     wave.clear();
  38.     wave.push_back(pair<int, int>(x, y));
  39.     while (map[x][y] != 0)
  40.     {
  41.         for (int d = 0; d < 4; ++d)
  42.         {
  43.             int nx = x + dx[d];
  44.             int ny = y + dy[d];
  45.             if (map[x][y] - 1 == map[nx][ny])
  46.             {
  47.                 x = nx;
  48.                 y = ny;
  49.                 wave.push_back(pair<int, int>(x, y));
  50.                 break;
  51.             }
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement