Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication1.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <iostream>
- #include <vector>
- #include <set>
- using namespace std;
- set<pair<int, int> > pestilence(set < pair<int, int> > apples, int x, int y, int rows, int cols) {
- set<pair<int, int> > tempCoord;
- if (y > 0)
- tempCoord.insert(make_pair(x, y - 1));
- if ( x > 0)
- tempCoord.insert(make_pair(x - 1, y));
- if (x+1 <= rows)
- tempCoord.insert(make_pair(x + 1, y));
- if (y+1 <= cols)
- tempCoord.insert(make_pair(x, y + 1));
- return tempCoord;
- }
- struct Contained {
- };
- int main()
- {
- int rows, cols, days;
- set<pair <int, int> > badApple;
- set<pair <int, int> > badApplesNew;
- cin >> rows >> cols >> days;
- int bads;
- cin >> bads;
- for (int i = 0; i < bads; i++) {
- int x, y;
- cin >> x >> y;
- badApple.insert(make_pair(x, y));
- }
- for (int i = 1; i <= days; i++) {
- set<pair<int, int> >::iterator it = badApple.begin();
- for (it = badApple.begin(); it != badApple.end(); it++) {
- auto tempSet = pestilence(badApple, it->first, it->second, rows, cols);
- badApplesNew.insert(tempSet.begin(), tempSet.end());
- }
- badApple.insert(badApplesNew.begin(), badApplesNew.end());
- }
- cout << badApple.size() << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement