【链接】 我是链接,点我呀:)

【题意】

在这里输入题意

【题解】

发现根本不用存节点信息。
遇到了叶子节点且为黑色,就直接覆盖矩阵就好(因为是并集);

【代码】

#include <bits/stdc++.h>
using namespace std; const int N = (1 << 5) + 10; string s;
int pos, bo[N][N]; void fugai(int x1, int y1, int x2, int y2) {
for (int i = x1; i <= x2; i++)
for (int j = y1; j <= y2; j++)
bo[i][j] = 1;
} void dfs(int x1, int y1, int x2, int y2) {
if (s[pos] == 'f' || s[pos] == 'e') {
if (s[pos] == 'f') {
fugai(x1, y1, x2, y2);
}
return;
}
int len = (x2 - x1 + 1) / 2;
pos++;
dfs(x1, y1 + len, x1 + len - 1, y1 + len + len - 1);
pos++;
dfs(x1, y1, x1 + len - 1, y1 + len - 1);
pos++;
dfs(x1 + len, y1, x1 + len + len - 1, y1 + len - 1);
pos++;
dfs(x1 + len, y1 + len, x1 + len + len - 1, y1 + len + len - 1);
} int main() {
//freopen("rush.txt", "r", stdin);
int T;
scanf("%d", &T);
while (T--) {
memset(bo, 0, sizeof bo);
cin >> s;
pos = 0;
dfs(1, 1, 32, 32);
cin >> s;
pos = 0;
dfs(1, 1, 32, 32);
int cnt = 0;
for (int i = 1; i <= 32; i++)
for (int j = 1; j <= 32; j++)
cnt += bo[i][j];
printf("There are %d black pixels.\n", cnt);
}
return 0;
}

【例题 6-11 UVA-297】Quadtrees的更多相关文章

  1. UVa 297 Quadtrees(树的递归)

    Quadtrees 四分树就是一颗一个结点只有4个儿子或者没有儿子的树 [题目链接]UVa 297 Quadtrees [题目类型]树的递归 &题意: 一个图片,像素是32*32,给你两个先序 ...

  2. UVA.297 Quadtrees (四分树 DFS)

    UVA.297 Quadtrees (四分树 DFS) 题意分析 将一个正方形像素分成4个小的正方形,接着根据字符序列来判断是否继续分成小的正方形表示像素块.字符表示规则是: p表示这个像素块继续分解 ...

  3. uva 297 quadtrees——yhx

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

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

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

  5. UVa 297 Quadtrees -SilverN

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

  6. UVa 297 - Quadtrees

    题目:利用四叉树处理图片,给你两张黑白图片的四叉树,问两张图片叠加后黑色的面积. 分析:搜索.数据结构.把图片分成1024块1*1的小正方形,建立一位数组记录对应小正方形的颜色. 利用递归根据字符串, ...

  7. UVA - 297 Quadtrees (四分树)

    题意:求两棵四分树合并之后黑色像素的个数. 分析:边建树边统计. #include<cstdio> #include<cstring> #include<cstdlib& ...

  8. 297 - Quadtrees (UVa)

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

  9. UVa 297 (四分树 递归) Quadtrees

    题意: 有一个32×32像素的黑白图片,用四分树来表示.树的四个节点从左到右分别对应右上.左上.左下.右下的四个小正方区域.然后用递归的形式给出一个字符串代表一个图像,f(full)代表该节点是黑色的 ...

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

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

随机推荐

  1. 《linux 内核全然剖析》编译linux 0.12 内核 Ubuntu 64bits 环境

    我×.. . 最终好了,大概3 4个小时吧...各种毛刺问题.终究还是闯过来了.. .. ubuntu2@ubuntu:~/Downloads/linux-0.00-050613/linux-0.00 ...

  2. C++ 递归位置排列算法及其应用

    废话不多说,我们先看一下位置排序的算法: #include <iostream> using namespace std; int n = 0; int m = 2; int l = 0; ...

  3. strongSwan IKEv2服务器配置

    strongSwan IKEv2服务器配置 资料来源 https://www.cl.cam.ac.uk/~mas90/resources/strongswan/ 经过大量的反复试验,我配置了一个str ...

  4. 将Firefox设置为使用远程DNS

    将Firefox设置为使用远程DNS 原文 https://www.my-proxy.com/blog/firefox-remote-dns 测试当前在用DNS              https: ...

  5. Outlook中设置会议的提醒

    https://support.office.com/en-us/article/Set-or-remove-reminders-7a992377-ca93-4ddd-a711-851ef359792 ...

  6. MyBatis自动生成代码之generatorConfig配置文件及其详细解读

    <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE generatorConfiguratio ...

  7. 搭建 GIT 服务器教程

  8. ipcalcIP地址计算

    ipcalc命令是一个简单的ip地址计算器,可以完成简单的IP地址计算任务. 语法 ipcalc(选项) 选项 -b:由给定的IP地址和网络掩码计算出广播地址: -h:显示给定UP地址所对应的主机名: ...

  9. SVN无法提交,路径找不到问题的解决方案

    自己有了个云服务器,只在上面搭建了几个博客网站(小雷网等). 我自己的代码,保存在SVNChina上,每年99元.(私人的付费,开源的免费) 云服务器,闲着也是闲着,决定在上面搭建一个属于自己的SVN ...

  10. 如何优雅的写UI——(4)选项卡美化

    现在做出来的选项卡实在太丑的,咱们怎么把他弄得好看一点呢 tabctrl是可以添加icon图标的,那派生与tabctrl的mfctabctrl肯定也能添加图标,他们两个添加图标的原理一样,但是还是有点 ...