Description

A quadtree is a representation format used to encode images. The fundamental idea 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 image is represented by a parent node, while the four quadrants are represented by four child nodes, in a predetermined order.

Of course, if the whole image is a single color, it can be represented by a quadtree consisting of a single node. In general, a quadrant needs only to be subdivided if it consists of pixels of different colors. As a result, the quadtree need not be of uniform depth.

A modern computer artist works with black-and-white images of units, for a total of 1024 pixels per image. One of the operations he performs is adding two images together, to form a new image. In the resulting image a pixel is black if it was black in at least one of the component images, otherwise it is white.

This particular artist believes in what he calls the preferred fullness: for an image to be interesting (i.e. to sell for big bucks) the most important property is the number 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.

Input Specification

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 parent node, the letter 'f' (full) a black quadrant and the letter 'e' (empty) a white quadrant. It is guaranteed that each string represents a valid quadtree, while the depth of the tree is not more than 5 (because each pixel has only one color).

Output Specification

For each test case, print on one line the text 'There are X black pixels.', where X is the number of black pixels in the resulting image.

Example Input

3
ppeeefpffeefe
pefepeefe
peeef
peefe
peeef
peepefefe

Example Output

There are 640 black pixels.
There are 512 black pixels.
There are 384 black pixels.
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <iomanip>
#include <cstdlib>
#include <sstream>
using namespace std;
const int INF=0x5fffffff;
const double EXP=1e-;
const int mod=;
const int MS=;
const int len=;
char str[MS];
int buf[len][len];
int ans;
//2 1
//3 4 void draw(const char *s,int &p,int r,int c,int w)
{
char ch=s[p++];
if(ch=='p')
{
draw(s,p,r,c+w/,w/); //
draw(s,p,r,c,w/); //
draw(s,p,r+w/,c,w/); //
draw(s,p,r+w/,c+w/,w/);//
}
else if(ch=='f') //处理黑色像素
{
for(int i=r;i<r+w;i++)
for(int j=c;j<c+w;j++)
{
if(buf[i][j]==) //两个图像的相同的位置都是黑色像素的话,
{ //是算一个的,buf其标记的作用
buf[i][j]=;
ans++;
}
}
}
} int main()
{
int T;
scanf("%d",&T);
while(T--)
{
memset(buf,,sizeof(buf));
ans=;
int p=;
scanf("%s",str);
draw(str,p,,,len);
scanf("%s",str);
p=;
draw(str,p,,,len);
printf("There are %d black pixels.\n",ans);
}
return ;
}
 

Quadtrees--四叉树的更多相关文章

  1. d3浅谈

    d3是一个及其庞大的库,有20个模块,大小也达到了216kb,是JQ1.x的2倍多,JQ3.x的3倍多,JQ本来就挺笨重的一个库,d3更是如此,但是它的功能确实很强悍~ d3的定位是一个科学计算库,并 ...

  2. UVA 297 Quadtrees(四叉树建树、合并与遍历)

    <span style="font-size: 18pt; font-family: Arial, Helvetica, sans-serif; background-color: r ...

  3. 【紫书】Quadtrees UVA - 297 四叉树涂色

    题意:前序遍历给出两个像素方块.求两个方块叠加后有几个黑色格子. 题解:每次读进来一个方块,就在二维数组上涂色.每次把白色涂黑就cnt++: 具体递归方法是以右上角坐标与边长为参数,每次通过几何规律往 ...

  4. [LeetCode] Quad Tree Intersection 四叉树相交

    A quadtree is a tree data in which each internal node has exactly four children: topLeft, topRight,  ...

  5. js实现四叉树算法

    最近在看canvas动画方面教程,里面提到了采用四叉树检测碰撞.之前也看到过四叉树这个名词,但是一直不是很懂.于是就又找了一些四叉树方面的资料看了看,做个笔记,就算日后忘了,也可以回来看看. Quad ...

  6. [译]2D空间中使用四叉树Quadtree进行碰撞检测优化

    操作系统:Windows8.1 显卡:Nivida GTX965M 开发工具:Unity2017.2.0f3 原文出处 : Quick Tip: Use Quadtrees to Detect Lik ...

  7. 地图四叉树一般用在GIS中,在游戏寻路中2D游戏中一般用2维数组就够了

    地图四叉树一般用在GIS中,在游戏寻路中2D游戏中一般用2维数组就够了 四叉树对于区域查询,效率比较高. 原理图

  8. HTML5实现3D和2D可视化QuadTree四叉树碰撞检测

    QuadTree四叉树顾名思义就是树状的数据结构,其每个节点有四个孩子节点,可将二维平面递归分割子区域.QuadTree常用于空间数据库索引,3D的椎体可见区域裁剪,甚至图片分析处理,我们今天介绍的是 ...

  9. HT for Web可视化QuadTree四叉树碰撞检测

    QuadTree四叉树顾名思义就是树状的数据结构,其每个节点有四个孩子节点,可将二维平面递归分割子区域.QuadTree常用于空间数据库索引,3D的椎体可见区域裁剪,甚至图片分析处理,我们今天介绍的是 ...

  10. uva 297 quadtrees——yhx

    Quadtrees  A quadtree is a representation format used to encode images. The fundamental idea behind ...

随机推荐

  1. 第三百五十五天 how can I 坚持

    快一年了,三百五十五天了,等写个程序算算时间,看看日期和天数能不能对的上,哈哈. 计划还是未制定,天气预报还是没有写完,立马行动,发完这个博客,立马行动. 计划:设计模式1个月,三大框架3个月,计算机 ...

  2. Linux下的paste合并命令详解

    paste单词意思是粘贴.该命令主要用来将多个文件的内容合并,与cut命令完成的功能刚好相反. 粘贴两个不同来源的数据时,首先需将其分类,并确保两个文件行数相同.paste将按行将不同文件行信息放在一 ...

  3. [原创]Devexpress XtraReports 系列 2 创建表格报表

    昨天发表了Devexpress XtraReports系列开篇,今天我们继续. 今天的主题是创建表格报表. 首先我们来看看最后实现的效果.Demo最后附上. 接下来开始讲解如何一步一步做出这个报表: ...

  4. USB开发库文件分析

    stm32f10x_it.c: 该文件中包含 USB 中断服务程序,由于 USB 中断有很多情况,这里的中断服务程序只是调用 usb_Istr.c 文件中的 USB_Istr 函数,由 USB_Ist ...

  5. hdu 1176 免费馅饼(数塔类型)

    http://acm.hdu.edu.cn/showproblem.php?pid=1176 免费馅饼 Time Limit: 2000/1000 MS (Java/Others)    Memory ...

  6. jgroups 常见概念

    组播(Multicast)传输:在发送者和每一接收者之间实现点对多点网络连接. 单播(Unicast)传输:在发送者和每一接收者之间实现点对点网络连接. 广播(Broadcast)传输:是指在IP子网 ...

  7. 在Ribbon中,中文换行位置不对怎么办

    在Ribbon代码的编写时,关于UI上面设置Button的中文字,经常会出现不想换行的地方换行的情况,比如下图: 我如果希望中国一行,然后只有一行怎么办呢. 网上流传的很多方法就是直接加空格,但是很遗 ...

  8. java dbcp连接池的使用

    package com.jb.jubmis.comm; import java.sql.Connection;import java.sql.ResultSet;import java.sql.SQL ...

  9. js全局变量

    在做东钿微信公众号 ,首页有房产评估和产调,有个checkbox ,点击则选中使用积分,取消选中则不使用积分,html结构和css样式都一样,唯一不一样的就是数据不一样,于是我就分开来写,没有写同一个 ...

  10. OC:习题来自平时搜索

    == 第一部分 ==  类变量的@protected ,@private,@public,@package,声明各有什么含义?写一个标准宏MIN,这个宏输入两个参数并返回较小的一个?面向对象的三大特征 ...