1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
| /*
uva297
the std is wrong, str should be larger
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
using namespace std;
int t;
const int maxa=33;
const int maxn=1033;
char s[maxn*maxn];
bool pic[maxa][maxa];
int cnt;
void draw(char* s,int& pos,int x,int y,int a)
{
++pos;
if(s[pos]=='p')
{
draw(s,pos,x,y+a/2,a/2);
draw(s,pos,x,y,a/2);
draw(s,pos,x+a/2,y,a/2);
draw(s,pos,x+a/2,y+a/2,a/2);
}
else if(s[pos]=='f')
{
for(int i=x;i<=x+a-1;++i)
for(int j=y;j<=y+a-1;++j)
if(!pic[i][j])
pic[i][j]=true,++cnt;
}
}
int main()
{
freopen("uva297_2.in","r",stdin);
freopen("uva297.out","w",stdout);
for(scanf("%d\n",&t);t;--t)
{
memset(pic,0,sizeof(pic));
cnt=0;
for(int i=1;i<=2;++i)
{
scanf("%s",s);
int p=-1;
draw(s,p,1,1,32);
}
printf("There are %d black pixels.\n",cnt);
}
return 0;
}
|