-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathP297.cpp
51 lines (47 loc) · 1.38 KB
/
P297.cpp
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
#include <iostream>
#include <stdio.h>
#include <cstring>
#define SIDE 32
#define SIZE 1024
typedef std::string String;
void paintPixels(bool *pixels, int &si, String &s, int xMin, int xMax, int yMin, int yMax) {
//std::cerr << "painting for " << s[si] << ", x [" << xMin << ";" << xMax << "], y [" << yMin << ";" << yMax << "[" << std::endl;
char c = s[si++];
if(c == 'f') { // f => black. Paint all:
for(int x = xMin; x < xMax; ++x) {
for(int y = yMin; y < yMax; ++y) {
pixels[y*SIDE + x] = true;
}
}
}
else if(c == 'p') {// Recurse
paintPixels(pixels, si, s, xMin, (xMin+xMax)/2, yMin, (yMin+yMax)/2);
paintPixels(pixels, si, s, (xMin+xMax)/2, xMax, yMin, (yMin+yMax)/2);
paintPixels(pixels, si, s, xMin, (xMin+xMax)/2, (yMin+yMax)/2, yMax);
paintPixels(pixels, si, s, (xMin+xMax)/2, xMax, (yMin+yMax)/2, yMax);
}
}
int main() {
bool pixels[SIZE];
int n;
String s;
std::cin >> n;
for(int cas = 0; cas < n; ++cas) {
for(int i = 0; i < SIZE; ++i)
pixels[i] = false;
//memset(pixels, false, SIZE);
int si = 0;
std::cin >> s;
paintPixels(pixels, si, s, 0, SIDE, 0, SIDE);
si = 0;
std::cin >> s;
paintPixels(pixels, si, s, 0, SIDE, 0, SIDE);
int ret = 0;
for(int i = 0; i < SIZE; ++i) {
if(pixels[i])
++ret;
}
std::cout << "There are " << ret << " black pixels." << std::endl;
}
return 0;
}