uva297

제목 설명:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=19243
//          ,        
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;
const int maxn = 1024 + 10;

char str[maxn];
int flag[32][32], cnt;      //flag     ,                 ,              

void draw(const char* s, int &p, int r, int c, int w) {
    //  s     (r, c)   ,w      , p     s     
    char ch = s[p++];
    if(ch == 'p') { //         ,     
        draw(s, p, r,           c,          w/2);      //         ,         
        draw(s, p, r,           c+w/2, w/2);
        draw(s, p, r+w/2,   c,          w/2);
        draw(s, p, r+w/2,   c+w/2, w/2);
    }
    else if(ch == 'f') {
        for(int i = r; i < r + w; i++)
            for(int j = c; j < c + w; j++)
                if(flag[i][j] == 0)      //    
                {   flag[i][j] = 1;    cnt++;  }
    }
}

int main()
{
    int T;
    scanf("%d", &T);

    while(T--) {
        cnt = 0;
        memset(flag, 0, sizeof(flag));

        for(int i = 0; i < 2; i++) {
            scanf("%s", str);
            int p = 0;
            draw(str, p, 0, 0, 32);
        }

        printf("There are %d black pixels.
"
, cnt); } return 0; }

좋은 웹페이지 즐겨찾기