Advertisement
Guest User

Untitled

a guest
Jan 17th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.09 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. ifstream in("imagine.in");
  7. ofstream out("imagine.out");
  8.  
  9. const int nMax = 255;
  10. bool a[nMax][nMax];
  11. int n;
  12. int rasp = 0;
  13.  
  14. void citire()
  15. {
  16.     in >> n;
  17.     for(int i = 1; i <= n; ++i)
  18.         for(int j = 1; j <= n; ++j)
  19.             in >> a[i][j];
  20. }
  21.  
  22. void rez(int startX, int startY, int stopX, int stopY)
  23. {
  24.     bool exista[2];
  25.     exista[0] = false;
  26.     exista[1] = false;
  27.     for(int i = startX; i <= stopX; ++i)
  28.         for(int j = startY; j <= stopY; ++j)
  29.         {
  30.             if(exista[0] && exista[1])
  31.                 break;
  32.             exista[a[i][j]] = true;
  33.         }
  34.     if(exista[0] && exista[1])
  35.     {
  36.         int medX = (startX + stopX) / 2;
  37.         int medY = (startY + stopY) / 2;
  38.         rez(medX + 1, startY, stopX, medY);
  39.         rez(startX, startY, medX, medY);
  40.         rez(medX + 1, medY + 1, stopX, stopY);
  41.         rez(startX, medY + 1, medX, stopY);
  42.         rasp++;
  43.     }
  44.     else
  45.         rasp += 2;
  46. }
  47.  
  48. int main()
  49. {
  50.     citire();
  51.     rez(1, 1, n, n);
  52.     out << rasp;
  53.     return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement