Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. #include <iostream>
  2. #include <queue>
  3. using namespace std;
  4. struct Point {
  5. int row, column;
  6. Point* top;
  7. Point* bottom;
  8. Point* left;
  9. Point* right;
  10. Point(int row, int column){
  11. this->row = row;
  12. this->column = column;
  13. top = nullptr;
  14. bottom = nullptr;
  15. left = nullptr;
  16. right = nullptr;
  17. }
  18. };
  19. void printTable(int** definiteArray, int rows, int columns) {
  20. for (int i = rows; i >= 1; i--) {
  21. for (int j = 1; j <= columns ; j++) {
  22. cout << definiteArray[i][j] << " ";
  23. }
  24. cout << endl;
  25. }
  26. cout << endl << endl;
  27. }
  28. void fulfillTable(int** definiteArray, int rows, int columns) {
  29. for (int i = 1; i <= rows; i++) {
  30. for (int j = 1; j <= columns; j++) {
  31. definiteArray[i][j] = 0;
  32. }
  33. }
  34. }
  35. int main() {
  36. int rows, columns;
  37. int numberOfDays;
  38. cin >> rows >> columns >> numberOfDays;
  39. int** table = new int*[rows + 1];
  40. for (int i = 0; i <= rows + 1; i++) {
  41. table[i] = new int[columns + 1];
  42. }
  43. fulfillTable(table, rows, columns);
  44. int counterOfRottenApples = 0;
  45. queue<Point> currentRotten;
  46. int row, column;
  47. while(cin >> row >> column){
  48. Point* current = new Point(row, column);
  49. currentRotten.push(*current);
  50. table[row][column] = 1;
  51. counterOfRottenApples++;
  52. }
  53. //printTable(table, rows, columns);
  54. queue<Point> temporary;
  55. for (int i = 0; i < numberOfDays; i++) {
  56. while (!currentRotten.empty()) {
  57. int temporaryRow = currentRotten.front().row;
  58. int temporaryColumn = currentRotten.front().column;
  59. if (table[temporaryRow - 1][temporaryColumn] != 1
  60. && temporaryRow - 1 >= 1){
  61.  
  62. counterOfRottenApples++;
  63. table[temporaryRow - 1][temporaryColumn] = 1;
  64. Point* pointToAdd = new Point(temporaryRow - 1, temporaryColumn);
  65. temporary.push(*pointToAdd);
  66. }
  67. if (temporaryRow + 1 <= rows
  68. && table[temporaryRow + 1][temporaryColumn] != 1) {
  69.  
  70. table[temporaryRow + 1][temporaryColumn] = 1;
  71. counterOfRottenApples++;
  72. Point* pointToAdd = new Point(temporaryRow + 1, temporaryColumn);
  73. temporary.push(*pointToAdd);
  74. }
  75. if (temporaryColumn - 1 >= 1 && table[temporaryRow][temporaryColumn - 1] != 1) {
  76.  
  77. counterOfRottenApples++;
  78. table[temporaryRow][temporaryColumn - 1] = 1;
  79. Point* pointToAdd = new Point(temporaryRow, temporaryColumn - 1);
  80. temporary.push(*pointToAdd);
  81. }
  82. if (temporaryColumn + 1 <= columns && table[temporaryRow][temporaryColumn + 1] != 1) {
  83.  
  84. counterOfRottenApples++;
  85. table[temporaryRow][temporaryColumn + 1] = 1;
  86. Point* pointToAdd = new Point(temporaryRow, temporaryColumn + 1);
  87. temporary.push(*pointToAdd);
  88. }
  89. currentRotten.pop();
  90. //printTable(table, rows, columns);
  91. }
  92. while (!temporary.empty()) {
  93. currentRotten.push(temporary.front());
  94. temporary.pop();
  95. }
  96. //printTable(table, rows, columns);
  97. }
  98. cout << (rows * columns) - counterOfRottenApples;
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement