Advertisement
RoshHoul

Apples2

Jan 27th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.31 KB | None | 0 0
  1. // ConsoleApplication1.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include <vector>
  7. #include <set>
  8.  
  9. using namespace std;
  10.  
  11. set<pair<int, int> > pestilence(set < pair<int, int> > apples, int x, int y, int rows, int cols) {
  12.  
  13.     set<pair<int, int> > tempCoord;
  14.  
  15.  
  16.     if (y > 0)
  17.         tempCoord.insert(make_pair(x, y - 1));
  18.  
  19.     if ( x > 0)
  20.         tempCoord.insert(make_pair(x - 1, y));
  21.    
  22.     if (x+1 <= rows)
  23.         tempCoord.insert(make_pair(x + 1, y));
  24.    
  25.     if (y+1 <= cols)
  26.         tempCoord.insert(make_pair(x, y + 1));
  27.  
  28.  
  29.         return tempCoord;
  30. }
  31.  
  32. struct Contained {
  33.  
  34. };
  35.  
  36. int main()
  37. {
  38.     int rows, cols, days;
  39.     set<pair <int, int> > badApple;
  40.     set<pair <int, int> > badApplesNew;
  41.  
  42.     cin >> rows >> cols >> days;
  43.  
  44.     int bads;
  45.     cin >> bads;
  46.  
  47.     for (int i = 0; i < bads; i++) {
  48.         int x, y;
  49.         cin >> x >> y;
  50.         badApple.insert(make_pair(x, y));
  51.        
  52.     }
  53.  
  54.  
  55.  
  56.     for (int i = 1; i <= days; i++) {
  57.         set<pair<int, int> >::iterator it = badApple.begin();
  58.         for (it = badApple.begin(); it != badApple.end(); it++) {
  59.             auto tempSet = pestilence(badApple, it->first, it->second, rows, cols);
  60.             badApplesNew.insert(tempSet.begin(), tempSet.end());
  61.         }
  62.         badApple.insert(badApplesNew.begin(), badApplesNew.end());
  63.     }
  64.  
  65.     cout << badApple.size() << endl;
  66.  
  67.     return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement