Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- ifstream in("imagine.in");
- ofstream out("imagine.out");
- const int nMax = 255;
- bool a[nMax][nMax];
- int n;
- int rasp = 0;
- void citire()
- {
- in >> n;
- for(int i = 1; i <= n; ++i)
- for(int j = 1; j <= n; ++j)
- in >> a[i][j];
- }
- void rez(int startX, int startY, int stopX, int stopY)
- {
- bool exista[2];
- exista[0] = false;
- exista[1] = false;
- for(int i = startX; i <= stopX; ++i)
- for(int j = startY; j <= stopY; ++j)
- {
- if(exista[0] && exista[1])
- break;
- exista[a[i][j]] = true;
- }
- if(exista[0] && exista[1])
- {
- int medX = (startX + stopX) / 2;
- int medY = (startY + stopY) / 2;
- rez(medX + 1, startY, stopX, medY);
- rez(startX, startY, medX, medY);
- rez(medX + 1, medY + 1, stopX, stopY);
- rez(startX, medY + 1, medX, stopY);
- rasp++;
- }
- else
- rasp += 2;
- }
- int main()
- {
- citire();
- rez(1, 1, n, n);
- out << rasp;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement