zhukov000

Game Alive

Nov 8th, 2019
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.47 KB | None | 0 0
  1. #define loop(i,from,to) for (int i = from; i < to; ++i)
  2. #include <bits/stdc++.h>
  3.  
  4. using std::cin;
  5. using std::cout;
  6. using std::endl;
  7. using std::vector;
  8. using std::string;
  9. using std::map;
  10. using std::pair;
  11.  
  12. const int INF = 1e9+7;
  13. const double eps = 1e-6;
  14. bool f;
  15. pair<int, int> steps[] = { {-1, -1}, {-1, 0}, {-1, 1}, {0, 1}, {1, 1}, {1, 0}, {1, -1}, {0, -1} };
  16.  
  17. signed main() {
  18.   std::ios::sync_with_stdio(false);
  19.   cin.tie(0);
  20.   freopen("INPUT.TXT", "r", stdin);
  21.   int n, m, k; cin >> n >> m >> k;
  22.   char c;
  23.   vector< vector<int> > data(n, vector<int>());
  24.   loop(i, 0, n)
  25.     loop(j, 0, m) {
  26.       cin >> c;
  27.       if (c == '*')
  28.         data[i].emplace_back(1);
  29.       else
  30.         data[i].emplace_back(0);
  31.     }
  32.   vector< vector<int> > nd(n, vector<int>());
  33.   loop(cnt, 0, k) {
  34.     loop(i, 0, n)
  35.       loop(j, 0, m) {
  36.         int count_alive = 0;
  37.         for(auto step: steps)
  38.           count_alive += data[(i + step.first + n) % n][(j + step.second + m) % m];
  39.         nd[i].emplace_back(count_alive);
  40.       }
  41.     loop(i, 0, n)
  42.       loop(j, 0, m) {
  43.         if (data[i][j]) {
  44.           if (nd[i][j] < 2 || nd[i][j] > 3)
  45.             data[i][j] = 0;
  46.         }
  47.         else
  48.           if (nd[i][j] == 3)
  49.             data[i][j] = 1;
  50.       }
  51.     nd.assign(n, vector<int>());
  52.   }
  53.   loop(i, 0, n) {
  54.     loop(j, 0, m) {
  55.       if (data[i][j]) cout << "*";
  56.       else cout << ".";
  57.     }
  58.     cout << endl;
  59.   }
  60.   //std::cout << "Hello World!\n";
  61.   return 0;
  62. }
Add Comment
Please, Sign In to add comment