-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuva297.cpp
More file actions
62 lines (53 loc) · 1.26 KB
/
uva297.cpp
File metadata and controls
62 lines (53 loc) · 1.26 KB
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
53
54
55
56
57
58
59
60
61
62
#include <cstdio>
#include <cstring>
#include <iostream>
#include <sstream>
#include <algorithm>
using namespace std;
#define LeftTop k<<2
#define RightTop (k<<2)+1
#define LeftBot (k<<2)+2
#define RightBot (k<<2)+3
const int MAXN = 35;
const int MAGIC = 32;
int g[MAXN][MAXN];
char buf[1000000];
int res;
int bidx;
void put_on_tree(int k, int lx, int ly, int rx, int ry) {
// printf("%d| %d %d %d %d\n", k, lx, ly, rx, ry);
int mx = (lx + rx) >> 1, my = (ly + ry) >> 1;
if(buf[++bidx] == 'p') {
put_on_tree(LeftTop, lx, ly, mx, my);
put_on_tree(RightTop, mx+1, ly, rx, my);
put_on_tree(LeftBot, lx, my+1, mx, ry);
put_on_tree(RightBot, mx+1, my+1, rx, ry);
} else if(buf[bidx] == 'f')
for(int i = lx; i <= rx; ++i)
for(int j = ly; j <= ry; ++j)
if(g[j][i] == 0) {
res++;
g[j][i] = 1;
}
}
void solve() {
memset(g, 0, sizeof(g));
res = 0;
bidx = -1;
scanf("%s", buf);
put_on_tree(1, 0, 0, MAGIC-1, MAGIC-1);
bidx = -1;
scanf("%s", buf);
put_on_tree(1, 0, 0, MAGIC-1, MAGIC-1);
printf("There are %d black pixels.\n", res);
}
int main() {
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int n;
scanf("%d", &n);
while(n--) {
solve();
}
return 0;
}