UVA - 297 Quadtrees (四分树)
题意:求两棵四分树合并之后黑色像素的个数。

分析:边建树边统计。
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
typedef long long ll;
typedef unsigned long long llu;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const ll LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {, , -, };
const int dc[] = {-, , , };
const double pi = acos(-1.0);
const double eps = 1e-;
const int MAXN = + ;
const int MAXT = + ;
using namespace std;
char s[MAXN];
int vis[MAXT][MAXT];
int cnt;
void dfs(int &id, int r, int c, int len){
char cc = s[id++];//传参加自增,遍历每个元素
if(cc == 'p'){
dfs(id, r, c + len / , len / );//
dfs(id, r, c, len / );//
dfs(id, r + len / , c, len / );//
dfs(id, r + len / , c + len / , len / );//
}
else if(cc == 'f'){
for(int i = r; i < r + len; ++i){
for(int j = c; j < c + len; ++j){
if(!vis[i][j]){
vis[i][j] = ;
++cnt;
}
}
}
}
}
int main(){
int T;
scanf("%d", &T);
while(T--){
memset(vis, , sizeof vis);
cnt = ;
for(int i = ; i < ; ++i){
scanf("%s", s);
int id = ;
dfs(id, , , );
}
printf("There are %d black pixels.\n", cnt);
}
return ;
}
UVA - 297 Quadtrees (四分树)的更多相关文章
- UVA.297 Quadtrees (四分树 DFS)
UVA.297 Quadtrees (四分树 DFS) 题意分析 将一个正方形像素分成4个小的正方形,接着根据字符序列来判断是否继续分成小的正方形表示像素块.字符表示规则是: p表示这个像素块继续分解 ...
- UVa 297 Quadtrees(树的递归)
Quadtrees 四分树就是一颗一个结点只有4个儿子或者没有儿子的树 [题目链接]UVa 297 Quadtrees [题目类型]树的递归 &题意: 一个图片,像素是32*32,给你两个先序 ...
- uva 297 quadtrees——yhx
Quadtrees A quadtree is a representation format used to encode images. The fundamental idea behind ...
- UVa 297 Quadtrees -SilverN
A quadtree is a representation format used to encode images. The fundamental idea behind the quadtre ...
- UVa 297 - Quadtrees
题目:利用四叉树处理图片,给你两张黑白图片的四叉树,问两张图片叠加后黑色的面积. 分析:搜索.数据结构.把图片分成1024块1*1的小正方形,建立一位数组记录对应小正方形的颜色. 利用递归根据字符串, ...
- UVA 297 Quadtrees(四叉树建树、合并与遍历)
<span style="font-size: 18pt; font-family: Arial, Helvetica, sans-serif; background-color: r ...
- Quadtrees(四分树)
uva 297 Quadtrees Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu Subm ...
- UVa 297 (四分树 递归) Quadtrees
题意: 有一个32×32像素的黑白图片,用四分树来表示.树的四个节点从左到右分别对应右上.左上.左下.右下的四个小正方区域.然后用递归的形式给出一个字符串代表一个图像,f(full)代表该节点是黑色的 ...
- 四分树 (Quadtrees UVA - 297)
题目描述: 原题:https://vjudge.net/problem/UVA-297 题目思路: 1.依旧是一波DFS建树 //矩阵实现 2.建树过程用1.0来填充表示像素 #include < ...
随机推荐
- DONET三层架构开发初步
.NET三层架构开发初步 今天咱们来谈下三层架构.说到三层架构,搞过点程序的可能都知道三层架构的概念.但是对三层的精髓可能不是很了解. 首先说下自己对三层的理解,就是使用三个(多个)项目结合起来开发出 ...
- Clarkson不等式
- 《JavaScript高级程序设计》 读书笔记(一)
标签的位置 按照传统的做法,所有<script>元素都应该放在页面的<head>元素中,例如: <!DOCTYPE html> <html> <h ...
- [ExtJS5学习笔记]第十节 Extjs5新增特性之ViewModel和DataBinding
本文地址:http://blog.csdn.net/sushengmiyan/article/details/38612721 本文作者:sushengmiyan ------------------ ...
- Samba Linux和Windows互访
之前一直用的sshfs manager,但是会出现造成电脑黑屏的情况.网上也没找到其它类似的软件. 后面打算用Samba 直接搜到一篇很强大的文章. 1. 下载及安装Samba 推荐用yum来安装, ...
- 一个GCC4.6.3的奇妙问题的糊涂解决方案
因为工作中需要OpenCV,又不想用Windows,所以我就在Linux下编译安装OpenCV了.一开始,由于我的计算机不能安装ubuntu12.04,所以我安装了ubuntu13.04,opencv ...
- 推荐一个国外的vps
也是我遇到过的最廉价的国外的vps,稳定性还不错,用到如今没问题.唯一的缺点就是适合大的企业型的vps卖完了.... ..中文服务,中文界面. 能够用来FQ啊神马的. http://www.hi-vp ...
- 每天进步一点点——负载均衡之DNS域名解析
转载请说明出处:http://blog.csdn.net/cywosp/article/details/38017027 在上一篇文章(http://blog.csdn.net/cywosp/ ...
- 编写一个程序,从标准输入中读取若干string对象并查找连续重复出现的单词。所谓连续重复出现的意思是:一个单词后面紧跟着这个单词本身。要求记录连续重复出现的最大次数以及对应的单词
#include<iostream> #include<string> #include<vector> using namespace std; int main ...
- [000]socket通信--server和client实现的简单例子
在C语言中就学过scanf和printf,其实理解socket就跟这两个输入输出差不多,只不过是信息的传输而已. 1.TCP服务器端(server)的默认函数调用顺序: 按照上述的调用顺序,我们可以来 ...