Question: Quadtrees Description A quadtree is a representation format used to encode images. The fundamental i dea behind the quadtree is that any image can be

Quadtrees
Description
A quadtree is a representation format used to encode images. The fundamental i dea behind the quadtree is that any image can be split into four quadrants. Each quadrant may again be split in four sub quadrants, etc. In the quadtree, the imag e is represented by a parent node, while the four quadrants are represented by f our child nodes, in a predetermined order.
Of course, if the whole image is a single color, it can be represented by a quadtr ee consisting of a single node. In general, a quadrant needs only to be subdivide d if it consists of pixels of different color. As a result, the quadtree need not be of uniform depth.
A modern computer artist works with black and white images of 215215 unit s, for a total of 230 pixels per image. One of the operations be perform is addin g two images together, to form a new image. In the resulting image a pixel is bla ck if it was black in at least one of component images, otherwise it is white.
This particular artist believes in what be calls the preferred fullness: for an image to be interesting (i.e., to sell for big bucks) the most important property is the nu mber of filled (black) pixels in the image. So, before adding two images together, he would like to know how many pixels will be black in the resulting image. your job is to write a program that, given the quadtree representation of two images, calculates the number of pixels that are black in the image, which is the result of adding the two images together.
In the figure, the first example is shown (from top to bottom) as image, quadtree, pre-order string (defined below) and number of pixels. The quadrant numbering is shown at the top of the figure.
peipieeie
469762048
peivperie
ppeevirperie
+335544320
671088640
Input
The first line of input specifies the number of test cases (N) your program has to process.
The input for each test case is two strings, each string on its own line. The string is the pre-order representation of a quadtree, in which the letter p indicates a par ent node, the letter f(full) a black quadrant and the letter e (empty) a white quad rant. It is quaranteed that each string represents a valid quadtree which contains at most 20000 characters.
Output
For each test case, print on one line the text There are x black pixels. , wh ere x is the number of black pixels in the resulting image.
Sample Input 1
3
ppeeefpffeefe
pefepeefe
peeef
peefe
peeef
peepefefe
Sample Output 1
There are 671088640 black pixe is.
There are 536870912 black pixe is. There are 402653184 black pixe is.
Quadtrees Description A quadtree is a

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!