Quadtrees(四分树)
uva 297
Time Limit: 3000MS | Memory Limit: Unknown | 64bit IO Format: %lld & %llu |
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>
#define M(a) memset(a,0,sizeof(a))
using namespace std;
const int maxsize=+;
const int len=;
char s[maxsize];
int vis[maxsize][maxsize];
int cnt; void draw(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(!vis[i][j])
vis[i][j]=,cnt++;
}
} int main()
{
int T;
cin>>T;
while(T--)
{
cnt=;M(vis);
for(int i=;i<=;i++)
{
cin>>s;
int p=;
draw(s,p,,,len);
}
printf("There are %d black pixels.\n",cnt);
}
return ;
}
Quadtrees(四分树)的更多相关文章
- UVA.297 Quadtrees (四分树 DFS)
UVA.297 Quadtrees (四分树 DFS) 题意分析 将一个正方形像素分成4个小的正方形,接着根据字符序列来判断是否继续分成小的正方形表示像素块.字符表示规则是: p表示这个像素块继续分解 ...
- UVa 297 Quadtrees(树的递归)
Quadtrees 四分树就是一颗一个结点只有4个儿子或者没有儿子的树 [题目链接]UVa 297 Quadtrees [题目类型]树的递归 &题意: 一个图片,像素是32*32,给你两个先序 ...
- [C++]四分树(Quadtrees)
[本博文非博主原创,思路与题目均摘自 刘汝佳<算法竞赛与入门经典(第2版)>] 四分树Quadtrees 一幅图有1024个点, 可以对图平均分成4块, 并且子图也可以再往下分, 直到一个 ...
- UVa 297 (四分树 递归) Quadtrees
题意: 有一个32×32像素的黑白图片,用四分树来表示.树的四个节点从左到右分别对应右上.左上.左下.右下的四个小正方区域.然后用递归的形式给出一个字符串代表一个图像,f(full)代表该节点是黑色的 ...
- UVA - 297 Quadtrees (四分树)
题意:求两棵四分树合并之后黑色像素的个数. 分析:边建树边统计. #include<cstdio> #include<cstring> #include<cstdlib& ...
- Uva297 Quadtrees【递归建四分树】【例题6-11】
白书 例题6-11 用四分树来表示一个黑白图像:最大的图为根,然后按照图中的方式编号,从左到右对应4个子结点.如果某子结点对应的区域全黑或者全白,则直接用一个黑结点或者白结点表示:如果既有黑又有白,则 ...
- 四分树 (Quadtrees UVA - 297)
题目描述: 原题:https://vjudge.net/problem/UVA-297 题目思路: 1.依旧是一波DFS建树 //矩阵实现 2.建树过程用1.0来填充表示像素 #include < ...
- UVA806-Spatial Structures(四分树)
Problem UVA806-Spatial Structures Accept:329 Submit:2778 Time Limit: 3000 mSec Problem Description ...
- 搜索(四分树):BZOJ 4513 [SDOI2016 Round1] 储能表
4513: [Sdoi2016]储能表 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 395 Solved: 213[Submit][Status] ...
- UVa 806 四分树
题意: 分析: 类似UVa 297, 模拟四分树四分的过程, 就是记录一个左上角, 记录宽度wideth, 然后每次w/2这样递归下去. 注意全黑是输出0, 不是输出1234. #include &l ...
随机推荐
- POJ1279 Art Gallery 多边形的核
POJ1279 给一个多边形 求它的核的面积 所谓多边形的核 是多边形中的一个点集 满足其中的点与多边形边上的点的连线全部在多边形中 用多边形的每一条边所在的直线去切整个坐标平面 得到的一个凸包就是核 ...
- Java 泛型 五:泛型与数组
简介 上一篇文章介绍了泛型的基本用法以及类型擦除的问题,现在来看看泛型和数组的关系.数组相比于Java 类库中的容器类是比较特殊的,主要体现在三个方面: 数组创建后大小便固定,但效率更高 数组能追踪它 ...
- SVN请求认证信息
WIN10:C:\Users\Home目录\AppData\Roaming\Subversion Window Server 系统:C:\Users\Home目录\AppData\Roaming\Su ...
- bzoj 1867: [Noi1999]钉子和小球【dp】
设f[i][j]为掉到f[i][j]时的概率然后分情况随便转移一下就好 主要是要手写分数比较麻烦 #include<iostream> #include<cstdio> usi ...
- [App Store Connect帮助]三、管理 App 和版本(7)移除 App
若要在“我的 App”主视图中移除 App,要先将此 App 从 App Store 中移除,并将所有与之关联的 App 内购买项目下架. 此外,仅当 App 的所有版本均处于下列状态之一时方可移除: ...
- [Swift通天遁地]一、超级工具-(6)通过JavaScript(脚本)代码调用设备的源生程序
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- [Swift通天遁地]一、超级工具-(16)使用JTAppleCalendar制作美观的日历
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- JS制作一个创意数字时钟
通过js代码制作一个创意数字时钟 通过JS代码实现创意数字时钟效果如下:由数字化的卡通形象图片取代常规的数字显示当前实时北京时间.具体效果示例: 核心重点: (1)Date方法的初步了解 (2)构建模 ...
- HTML <input>标签属性
- 【杂文】5亿大质数表(5e8)
[杂文]\(5\) 亿大质数表(\(5e8\)) 在写哈希,刷数论题时曾一度想要查质数,\(F**k\) 百度文库数据又少,翻页蛋疼,还不给复制,真的是服了. 于是在我闲的蛋疼的时候就搞了个质数表出来 ...