Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <queue>
- using namespace std;
- struct Point {
- int row, column;
- Point* top;
- Point* bottom;
- Point* left;
- Point* right;
- Point(int row, int column){
- this->row = row;
- this->column = column;
- top = nullptr;
- bottom = nullptr;
- left = nullptr;
- right = nullptr;
- }
- };
- void printTable(int** definiteArray, int rows, int columns) {
- for (int i = rows; i >= 1; i--) {
- for (int j = 1; j <= columns ; j++) {
- cout << definiteArray[i][j] << " ";
- }
- cout << endl;
- }
- cout << endl << endl;
- }
- void fulfillTable(int** definiteArray, int rows, int columns) {
- for (int i = 1; i <= rows; i++) {
- for (int j = 1; j <= columns; j++) {
- definiteArray[i][j] = 0;
- }
- }
- }
- int main() {
- int rows, columns;
- int numberOfDays;
- cin >> rows >> columns >> numberOfDays;
- int** table = new int*[rows + 1];
- for (int i = 0; i <= rows + 1; i++) {
- table[i] = new int[columns + 1];
- }
- fulfillTable(table, rows, columns);
- int counterOfRottenApples = 0;
- queue<Point> currentRotten;
- int row, column;
- while(cin >> row >> column){
- Point* current = new Point(row, column);
- currentRotten.push(*current);
- table[row][column] = 1;
- counterOfRottenApples++;
- }
- //printTable(table, rows, columns);
- queue<Point> temporary;
- for (int i = 0; i < numberOfDays; i++) {
- while (!currentRotten.empty()) {
- int temporaryRow = currentRotten.front().row;
- int temporaryColumn = currentRotten.front().column;
- if (table[temporaryRow - 1][temporaryColumn] != 1
- && temporaryRow - 1 >= 1){
- counterOfRottenApples++;
- table[temporaryRow - 1][temporaryColumn] = 1;
- Point* pointToAdd = new Point(temporaryRow - 1, temporaryColumn);
- temporary.push(*pointToAdd);
- }
- if (temporaryRow + 1 <= rows
- && table[temporaryRow + 1][temporaryColumn] != 1) {
- table[temporaryRow + 1][temporaryColumn] = 1;
- counterOfRottenApples++;
- Point* pointToAdd = new Point(temporaryRow + 1, temporaryColumn);
- temporary.push(*pointToAdd);
- }
- if (temporaryColumn - 1 >= 1 && table[temporaryRow][temporaryColumn - 1] != 1) {
- counterOfRottenApples++;
- table[temporaryRow][temporaryColumn - 1] = 1;
- Point* pointToAdd = new Point(temporaryRow, temporaryColumn - 1);
- temporary.push(*pointToAdd);
- }
- if (temporaryColumn + 1 <= columns && table[temporaryRow][temporaryColumn + 1] != 1) {
- counterOfRottenApples++;
- table[temporaryRow][temporaryColumn + 1] = 1;
- Point* pointToAdd = new Point(temporaryRow, temporaryColumn + 1);
- temporary.push(*pointToAdd);
- }
- currentRotten.pop();
- //printTable(table, rows, columns);
- }
- while (!temporary.empty()) {
- currentRotten.push(temporary.front());
- temporary.pop();
- }
- //printTable(table, rows, columns);
- }
- cout << (rows * columns) - counterOfRottenApples;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement