Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.2 kB
2
Indexable
Never
#include<iostream>

using namespace std;

int a[128][128];
int dem0;
int dem1;
int n;


void cat(int i, int j, int row, int col)
{
	
	if(row == 1 && col == 1 ) 
	{
		if(a[i][j] ==1) dem1++;
		else if(a[i][j] ==0) dem0++;
		return;
	}
	bool check = true;
	for(int h=i; h < i+row-1; h++){
		if(check == false)break;
			for(int k= j; k < j+col-1; k++){
				if(a[h][k] == a[h][k+1] && a[h][k] == a[h+1][k] && a[h][k] == a[h+1][k+1]){
					check =true;}
				else{
					check =false;
					break;
				}
			}
	
	}
	if(check==true && a[i][j] ==0){
		dem0++;
		return;}
	if(check==true && a[i][j] ==1){
		dem1++;
		return;
	}
	if(check ==false){
	cat(i, j,row/2, col/2);
	cat(i, j+row/2,row/2, col/2);
	cat(i+row/2, j,row/2, col/2);
	cat(i+row/2, j+row/2,row/2, col/2);
	}
}
 int main(){
	 int test; 
	 cin >> test;
	 for(int tc =1; tc <= test; tc++){
		 cin >> n;
		 for(int i=0; i < n; i++){
			for(int j= 0; j < n; j++){
				cin >> a[i][j];
			}
		}
		dem0 = 0;
		dem1 = 0;
		
		cat(0 ,0, n ,n);
			
		cout << "Case" << " " << "#" << tc << endl;
		cout << dem0 << " "<< dem1 << endl;
	 }
	 
	 return 0;
 }