https://vjudge.net/problem/UVA-297
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
bool b[33][33];
int color(int x,int y,int r){
char c=getchar();
if(c=='p'){
color(x,y,r/2);
color(x,y+r/2,r/2);
color(x+r/2,y,r/2);
color(x+r/2,y+r/2,r/2);
}else if(c=='f'){
for(int i=0;i<r;i++)
for(int j=0;j<r;j++)
b[x+i][y+j]=true;
}
}
int main(){
int n;
scanf("%d",&n);
while(n--){
memset(b,0,sizeof(b));
getchar();
color(1,1,32);
getchar();
color(1,1,32);
int ans=0;
for(int i=1;i<=32;i++)
for(int j=1;j<=32;j++)
if(b[i][j])ans++;
printf("There are %d black pixels.\n",ans);
}
}