uva 297

来源:互联网 发布:网络链路冗余技术 编辑:程序博客网 时间:2024/06/06 02:16

四分树,递归画出四块区域

#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;const int len = 32;const int maxn = 1024 + 20; int square[len][len],cnt;char s[maxn];void draw(char* s,int& pos,int p,int q,int r){    char ch = s[pos++];    if(ch == 'p'){        draw(s,pos,p,q+r/2,r/2);        draw(s,pos,p,q,r/2);        draw(s,pos,p+r/2,q,r/2);        draw(s,pos,p+r/2,q+r/2,r/2);    }    else if(ch == 'f'){        for(int i = p;i<p+r;i++){            for(int j=q;j<q+r;j++){                if(square[i][j]==0) {                    cnt++;                    square[i][j] = 1;                }            }        }    }}int main(){    int T;    cin>>T;    while(T--){        memset(square,0,sizeof(square));        cnt = 0;        for(int i=0;i<2;i++){            scanf("%s",s);            int pos = 0;            draw(s,pos,0,0,len);        }        cout<<"There are "<<cnt<<" black pixels."<<endl;    }    return 0;}
0 0