思路:根据题意,每个字母都是代表一个正方形的方块,那么我们要表示这个正方形就只需要左上角的坐标和宽度,字母'P'表示这个方块里面有黑块,但是不是全部都是,所有要针对这个方块继续递归建树,‘f’表示这个方块全是黑色的,那么就可以开始统计数目了。‘e’就直接忽略丢就好了。
点击题目链接
/***************************************** Author :Crazy_AC(JamesQi) Time :2015 File Name : *****************************************/ // #pragma comment(linker, "/STACK:1024000000,1024000000") #include <iostream> #include <algorithm> #include <iomanip> #include <sstream> #include <string> #include <stack> #include <queue> #include <deque> #include <vector> #include <map> #include <set> #include <stdio.h> #include <string.h> #include <math.h> #include <stdlib.h> #include <limits.h> using namespace std; #define MEM(a,b) memset(a,b,sizeof a) typedef long long LL; typedef unsigned long long ULL; typedef pair<int,int> ii; const int inf = 1 << 30; const int INF = 0x3f3f3f3f; const int MOD = 1e9 + 7; inline int Readint(){ char c = getchar(); while(!isdigit(c)) c = getchar(); int x = 0; while(isdigit(c)){ x = x * 10 + c - '0'; c = getchar(); } return x; } char s[10000]; int col[100][100]; int cnt; const int len = 32; void solve(const char *s,int &p,int x,int y,int w){ char tmp = s[p++]; if (tmp == 'p'){ solve(s,p,x,y + w / 2,w / 2); solve(s,p,x,y,w / 2); solve(s,p,x + w / 2,y,w / 2); solve(s,p,x + w / 2,y + w / 2,w / 2); }else if (tmp == 'f'){ for (int i = x;i < x + w;i++){ for (int j = y;j < y + w;j++){ if(col[i][j] == 0){ col[i][j] = 1; cnt++; } } } } } int main() { // freopen("in.txt","r",stdin); // freopen("out.txt","w",stdout); int t; scanf("%d",&t); while(t--){ memset(col, 0,sizeof col); cnt = 0; for (int i = 1;i <=2;i++){ scanf("%s",s); int p = 0; int len = 32; solve(s,p,0,0,len); } // printf("%d\n",cnt); printf("There are %d black pixels.\n",cnt); } return 0; }