Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <set>
- #include <queue>
- #include <iterator>
- class RottenApple
- {
- public:
- int x;
- int y;
- RottenApple(int x, int y)
- {
- this->x = x;
- this->y = y;
- }
- bool operator ==(const RottenApple& obj) const
- {
- if (this->x == obj.x && this->y == obj.y)
- return true;
- return false;
- }
- void print()
- {
- std::cout << this->x << " " << this->y << std::endl;
- }
- };
- bool operator<(const RottenApple& a, const RottenApple& b) {
- return a.x < b.x;
- }
- int main()
- {
- int row, column, days;
- std::cin >> row >> column >> days;
- std::set<RottenApple* > rotten_apples;
- std::queue<RottenApple*> queued_apples;
- int x, y;
- while (std::cin >> x >> y)
- {
- RottenApple* apple = new RottenApple(row - x, y - 1);
- queued_apples.push(apple);
- }
- for (int i = 0; i <= days; i++)
- {
- std::queue<RottenApple* > nextInLine;
- while (!queued_apples.empty())
- {
- RottenApple* apple = queued_apples.front();
- queued_apples.pop();
- rotten_apples.insert(apple);
- if (apple->x + 1 < row)
- {
- nextInLine.push(new RottenApple(apple->x + 1, apple->y));
- }
- if (apple->x - 1 >= 0)
- {
- nextInLine.push(new RottenApple(apple->x - 1, apple->y));
- }
- if (apple->y + 1 < column)
- {
- nextInLine.push(new RottenApple(apple->x, apple->y + 1));
- }
- if (apple->y - 1 >= 0)
- {
- nextInLine.push(new RottenApple(apple->x, apple->y - 1));
- }
- }
- queued_apples = nextInLine;
- }
- for (auto temp : rotten_apples)
- temp->print();
- std::cout << rotten_apples.size() << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement