#include <cstdio> int Color[1024] = {0}, move; char data[1366]; int deal(int a, int b) { if (data[move] == 'p') //判断该结点是否有 4 个子结点 for (int i = 0; i < 4; i++) { //判断这 4 个子结点是否还有子结点 move++; deal(a + i * (b - a) / 4 + (i != 0), a + (i + 1) * (b - a) / 4); } else if (data[move] == 'f') //如果该结点没有子结点且是黑色, 给其管辖区域上色 for (int i = a; i <= b; ++i) Color[i] = 1; return 0; } int main() { int t; while (scanf("%d", &t) != EOF) while (t--) { int sum = 0; for (int i = 0; i < 2; i++) { scanf("%s", data); move = 0; deal(0, 1023); } for (int i = 0; i < 1024; ++i) sum += Color[i], Color[i] = 0; printf("There are %d black pixels.\n", sum); } return 0; }