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 < ...
随机推荐
- MYSQL- 创建和删除临时表
临时表可能是非常有用的,在某些情况下,保持临时数据.最重要的是应该知道的临时表是,他们将当前的客户(www.111cn.net)端会话终止时被删除 当你创建临时表的时候,你可以使用temporary关 ...
- 剑指OFFER之第一个只出现一次的字符(九度OJ1283)
题目描述: 在一个字符串(1<=字符串长度<=10000,全部由大写字母组成)中找到第一个只出现一次的字符. 输入: 输入有多组数据每一组输入一个字符串. 输出: 输出第一个只出现一次的字 ...
- 如何使用validate.js进行动态添加和移除表单验证信息
表单是我们在开当中的常客,那么对表单的验证也是必须的,那么如何实现动态给表单添加验证规则呢? 方法: 1,动态添加验证规则 // 添加$("#addConnectUser").ru ...
- Android Error
[2016-03-27 13:00:51 - XWeChat] Dx warning: Ignoring InnerClasses attribute for an anonymous inner c ...
- node.js在windows下的学习笔记(7)---express的app.js的详细配置说明
var express = require('express'); var path = require('path'); var favicon = require('serve-favicon') ...
- node.js在windows下的学习笔记(6)---安装Express
Express是什么呢? express.js是nodejs的一个MVC开发框架,并且支持jade等多种模板.对于WEB应用程序而言,会有许多诸如模板和路由这样的公共模式在的,虽然也可以自己编写代码解 ...
- 彻底解决android读取中文txt的乱码(自动判断文档类型并转码
原文:http://blog.csdn.net/handsomedylan/article/details/6138400 public String convertCodeAndGetText(St ...
- js操作json添加元素和数据的方法
function addServerUrlToJson() { var json_tem = [{"name":"a","value":1} ...
- 五、Socket之UDP异步传输文件-实现传输中取消传送
上一篇文章四.Socket之UDP异步传输文件中,只实现了传输开始前拒绝接收文件,没有实现文件传输进行的时候取消传送,这篇文章中我们就来介绍怎样实现这个功能. 在传输过程中取消文件的传送,有很多地方要 ...
- C#_StringBuilder分离字符串实例
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Stri ...