Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <queue>
  4. #include <iterator>
  5.  
  6. using namespace std;
  7.  
  8. vector<vector<int>> field(100, vector<int> (100));
  9. vector<vector<int>> new_field(100, vector<int> (100));
  10.  
  11. vector<int> dx = {1, 1, 0, -1, -1, -1, 0, 1};
  12. vector<int> dy = {0, -1, -1, -1, 0, 1, 1, 1};
  13.  
  14. int color (int x, int y) {
  15. int cnt = 0;
  16. for (int i = 0; i < 8; i++) {
  17. int new_x = x + dx[i];
  18. int new_y = y + dy[i];
  19. if (new_x >= 0 && new_x <= 99 && new_y >= 0 && new_y <= 99 && field[new_x][new_y] == 1)
  20. cnt++;
  21. }
  22. if (field[x][y] == 0) {
  23. if (cnt == 3) {
  24. return 1;
  25. } else {
  26. return 0;
  27. }
  28. } else {
  29. if (cnt == 2 || cnt == 3)
  30. return 1;
  31. else
  32. return 0;
  33. }
  34. }
  35.  
  36.  
  37. int main()
  38. {
  39. field[50][50] = 1;
  40. field[50][51] = 1;
  41. field[50][52] = 1;
  42. field[51][50] = 1;
  43. for (int i = 0; i < 3; i++) {
  44. for (int x = 0; x < 100; x++)
  45. for (int y = 0; y < 100; y++) {
  46. new_field[x][y] = color(x, y);
  47. }
  48. field = new_field;
  49. }
  50.  
  51. int cnt = 0;
  52. for (int x = 0; x < 100; x++)
  53. for (int y = 0; y < 100; y++)
  54. if (field[x][y] == 1)
  55. cnt++;
  56.  
  57. cout << cnt << endl;
  58.  
  59. for (int i = 45; i < 55; i++) {
  60. for (int j = 45; j < 55; j++)
  61. cout << field[i][j] << " ";
  62. cout << endl;
  63. }
  64.  
  65. return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement