UVa 806 四分树
题意:
分析:
类似UVa 297, 模拟四分树四分的过程, 就是记录一个左上角, 记录宽度wideth, 然后每次w/2这样递归下去。 注意全黑是输出0, 不是输出1234。
#include <bits/stdc++.h>
using namespace std;
// 1 2
// 3 4
const int base5[] = {,,,,,,,};
int n;
string G[];
vector<int> code;
int dfs(int r, int c, int w,int num,int dep){
int lt[][] = {{},{r,c},{r,c+w/},{r+w/,c},{r+w/, c+w/}}; for(int i = ; i <= ; i++){
int all_black = , have_black = ; for(int j = lt[i][]; j < lt[i][] + w/; j++){
for(int k = lt[i][]; k < lt[i][] + w/; k++){
if(G[j][k] == ''){
all_black = ;
}
else {
have_black = ;
}
}
}
if(all_black == ){ if(w == ){//宽度为2四分,只有一个格子, 只能为白
continue;
}
if(have_black)
dfs(lt[i][], lt[i][], w/, num + base5[dep]*i, dep + );
}
else{
code.push_back(num + base5[dep] * i);
}
}
}
void print(int r, int c, int w, int dep,int decode, int dec){
int lt[][] = {{},{r,c},{r,c+w/},{r+w/,c},{r+w/, c+w/}};
if(decode == ){
for(int i = r; i < r + w; i++){
for(int j = c; j < c + w; j++ ){
G[i][j] = '';
}
}
return;
} dec = decode % ;
decode /= ; for(int i = ; i <= ; i++){
if(dec == i){
print(lt[i][], lt[i][], w/ , dep + ,decode, dec);
}
else continue;
}
}
int main(){
ios::sync_with_stdio(false);
int kase = ;
while(cin >> n && n){ if(kase > ) cout <<'\n';
cout << "Image "<<kase ++ << '\n'; if(n > ){
int flag = ;
for(int i = ; i < n; i++){
cin >> G[i];
for(int j = ; j < G[i].size(); j++){
if(G[i][j] == '') flag = ;
}
}
if(!flag){//特判全黑
cout << "0\n";
cout << "Total number of black nodes = 1"<< "\n";
continue; } if(n == ){//特判n = 1 全白。
cout << "Total number of black nodes = 0" << "\n";
continue;
} dfs(,,n,,);
sort(code.begin(), code.end());
for(int i = ; i < code.size(); i++){
cout << code[i];
if((i + ) % == || i == code.size() - )
cout <<'\n';
else cout << ' ';
} cout << "Total number of black nodes = "<< code.size() << '\n';
code.clear();
} else {
n = -n;
for(int i = ; i < n; i++){
G[i] = "";
G[i]. resize(n +);//string要更改size才能下标访问
}
int decode;
while(cin >> decode && decode != -){
print(,,n,,decode, );
}
for(int i = ; i < n; i++){
for(int j = ; j < n; j++){
if(G[i][j] == ''){
cout << '*';
}
else cout << '.';
}
cout << '\n';
}
}
} return ;
}
UVa 806 四分树的更多相关文章
- UVa 297 (四分树 递归) Quadtrees
题意: 有一个32×32像素的黑白图片,用四分树来表示.树的四个节点从左到右分别对应右上.左上.左下.右下的四个小正方区域.然后用递归的形式给出一个字符串代表一个图像,f(full)代表该节点是黑色的 ...
- UVa 297 四分树
感觉特别像那个分治的日程表问题.是f的话就填,否则就不填,然后同一个表填两次.那么就是最后的结果. #include <iostream> #include <cstring> ...
- UVA.297 Quadtrees (四分树 DFS)
UVA.297 Quadtrees (四分树 DFS) 题意分析 将一个正方形像素分成4个小的正方形,接着根据字符序列来判断是否继续分成小的正方形表示像素块.字符表示规则是: p表示这个像素块继续分解 ...
- UVA - 297 Quadtrees (四分树)
题意:求两棵四分树合并之后黑色像素的个数. 分析:边建树边统计. #include<cstdio> #include<cstring> #include<cstdlib& ...
- 四分树 (Quadtrees UVA - 297)
题目描述: 原题:https://vjudge.net/problem/UVA-297 题目思路: 1.依旧是一波DFS建树 //矩阵实现 2.建树过程用1.0来填充表示像素 #include < ...
- 搜索(四分树):BZOJ 4513 [SDOI2016 Round1] 储能表
4513: [Sdoi2016]储能表 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 395 Solved: 213[Submit][Status] ...
- [C++]四分树(Quadtrees)
[本博文非博主原创,思路与题目均摘自 刘汝佳<算法竞赛与入门经典(第2版)>] 四分树Quadtrees 一幅图有1024个点, 可以对图平均分成4块, 并且子图也可以再往下分, 直到一个 ...
- UVA806-Spatial Structures(四分树)
Problem UVA806-Spatial Structures Accept:329 Submit:2778 Time Limit: 3000 mSec Problem Description ...
- Uva297 Quadtrees【递归建四分树】【例题6-11】
白书 例题6-11 用四分树来表示一个黑白图像:最大的图为根,然后按照图中的方式编号,从左到右对应4个子结点.如果某子结点对应的区域全黑或者全白,则直接用一个黑结点或者白结点表示:如果既有黑又有白,则 ...
随机推荐
- BZOJ4571
BZOJ4571 Description Transmission Gate 给定n个数, m次询问, 每次询问[l,r]范围内的数加上x后异或b的最大值, x, b给出. \[n,m <= 2 ...
- [BZOJ1453]Dface双面棋盘
Description Input Output Sample Input Sample Output HINT 线段树+并查集,暴力记录和更新一些信息,详情见代码注解. #include<cm ...
- _bzoj1009 [HNOI2008]GT考试【矩阵加速dp】
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1009 比较不错的一道题,令f(i, j)表示考号匹配到i位,后j位为不吉利串的前j位,那么对 ...
- KMP HDOJ 4300 Clairewd's message
题目传送门 题意:完全不懂,最后还是看题解才理解了.第一行字符串是密文变成明文的规则,比如第二个样例:“qwertyuiopasdfghjklzxcvbnm”,‘q'对应的明文为’a','w'对应'b ...
- BFS(最短路) HDOJ 4308 Saving Princess claire_
题目传送门 题意:一个(r*c<=5000)的迷宫,起点'Y‘,终点'C',陷阱‘#’,可行路‘*’(每走一个,*cost),传送门P,问Y到C的最短路 分析:一道最短路问题,加了传送门的功能, ...
- 使用Maven将dubbox安装进资源仓库
dubbox网址:https://github.com/dangdangdotcom/dubbox dobbox版本:https://github.com/dangdangdotcom/dubbox/ ...
- Service官方教程(9)绑定服务时的注意事项
Binding to a Service Application components (clients) can bind to a service by calling bindService() ...
- Oracle报错:“ORA-18008: 无法找到 OUTLN 方案 ”的解决方案
Oracle报错:“ORA-18008: 无法找到 OUTLN 方案 ”的解决方案 2.修改replication_dependency_tracking参数 SQL> alter syst ...
- iOS---数据离线缓存
离线缓存 为了用户的体验,不需要每次打开App都加载新数据,或者重新请求数据,因此需要把每次浏览的数据保存起来,当下次打开软件时,首先从沙盒中加载数据:或者当软件未联网时,也只能从沙盒中加载旧数据. ...
- org.springframework.orm.hibernate4.support.OpenSessionInterceptor
/* * Copyright 2002-2014 the original author or authors. * * Licensed under the Apache License, Vers ...