JosepRivaille

P45829: Camps

Jun 5th, 2015
1,845
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.02 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5.  
  6. typedef vector<int> Row;
  7. typedef vector<Row> Matrix;
  8.  
  9. void erase(vector< vector<int> >& v, int x, int y, int& count) {
  10.     int f = v.size();
  11.     int c = v[0].size();
  12.     int i = x;
  13.     bool contains = false;
  14.     while (i < f and v[i][y] != 0) {
  15.         int j = y;
  16.         while (j < c and v[i][j] != 0) {
  17.             v[i][j] = 0;
  18.             contains = true;
  19.             ++j;
  20.         }
  21.         ++i;
  22.     }
  23.     if (contains) ++count;
  24. }  
  25.  
  26. int main() {
  27.     int f, c;
  28.     while (cin >> f >> c) {
  29.         Matrix M(f, Row(c));
  30.         for (int i = 0; i < f; ++i) {
  31.             for (int j = 0; j < c; ++j) {
  32.                 cin >> M[i][j];
  33.             }
  34.         }
  35.         int count = 0;
  36.         for (int i = 0; i < f; ++i) {
  37.             for (int j = 0; j < c; ++j) {
  38.                 if (M[i][j] != 0) {
  39.                     erase(M, i, j, count);
  40.                 }
  41.             }
  42.         }
  43.         cout << count << endl;
  44.     }
  45. }
  46.  
  47. //JosepRivaille
Advertisement
Add Comment
Please, Sign In to add comment