题意:

分析:

类似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 四分树的更多相关文章

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

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

  2. UVa 297 四分树

    感觉特别像那个分治的日程表问题.是f的话就填,否则就不填,然后同一个表填两次.那么就是最后的结果. #include <iostream> #include <cstring> ...

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

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

  4. UVA - 297 Quadtrees (四分树)

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

  5. 四分树 (Quadtrees UVA - 297)

    题目描述: 原题:https://vjudge.net/problem/UVA-297 题目思路: 1.依旧是一波DFS建树 //矩阵实现 2.建树过程用1.0来填充表示像素 #include < ...

  6. 搜索(四分树):BZOJ 4513 [SDOI2016 Round1] 储能表

    4513: [Sdoi2016]储能表 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 395  Solved: 213[Submit][Status] ...

  7. [C++]四分树(Quadtrees)

    [本博文非博主原创,思路与题目均摘自 刘汝佳<算法竞赛与入门经典(第2版)>] 四分树Quadtrees 一幅图有1024个点, 可以对图平均分成4块, 并且子图也可以再往下分, 直到一个 ...

  8. UVA806-Spatial Structures(四分树)

    Problem UVA806-Spatial Structures Accept:329  Submit:2778 Time Limit: 3000 mSec Problem Description ...

  9. Uva297 Quadtrees【递归建四分树】【例题6-11】

    白书 例题6-11 用四分树来表示一个黑白图像:最大的图为根,然后按照图中的方式编号,从左到右对应4个子结点.如果某子结点对应的区域全黑或者全白,则直接用一个黑结点或者白结点表示:如果既有黑又有白,则 ...

随机推荐

  1. Luogu P2735 电网【真·计算几何/Pick定理】By cellur925

    题目传送门 刷USACO偶然遇到的,可能是人生中第一道正儿八经的计算几何. 题目大意:在平面直角坐标系中给你一个以格点为顶点的三角形,求三角形中的整点个数. 因为必修5和必修2的阴影很快就想到了数学中 ...

  2. Java Genericity

    四.  Java Genericity 1.  Genericity 泛型 泛型 <T> 1. 泛型就是参数化类型 2. 作用:安全,方便 3. 适用于对多种数据类型执行相同功能的代码,主 ...

  3. Windows服务使用log4net记录日志

    该文章是系列文章 基于.NetCore和ABP框架如何让Windows服务执行Quartz定时作业 的其中一篇. 比较流行的日志组件有以下四种,Topshelf都有相应的组件提供 log4net NL ...

  4. LoadRunner_11破解教程完整版

    2017.12.17更正 qtm的LR11,如果是win10版本的电脑而且ie浏览器是11以上的请到loadrunner官网下载社区免费版,支持google,firefox,edge,ie11四大浏览 ...

  5. 2017 JUST Programming Contest 3.0 D. Dice Game

    D. Dice Game time limit per test 1.0 s memory limit per test 256 MB input standard input output stan ...

  6. Guilty Prince LightOJ - 1012

    Guilty Prince LightOJ - 1012 #include<cstdio> #include<cstring> ][]; int ans,h,w,T,TT; ] ...

  7. Android偏好设置(5)偏好设置界面显示多个分组,每个分组也有一个界面

    1.Using Preference Headers In rare cases, you might want to design your settings such that the first ...

  8. C++中的数学函数汇总

    math.h 数学函数库,一些数学计算的公式的具体实现是放在math.h里,具体有: 1 三角函数 double sin (double); double cos (double); double t ...

  9. angular.module 参数的意思

    定义一个module需要两个参数,第一个作为module的名字,第二个则是指出这个module都依赖哪些别的modules

  10. Win10 UWP开发:摄像头扫描二维码/一维码功能

    这个示例演示整合了Aran和微软的示例,无需修改即可运行. 支持识别,二维码/一维码,需要在包清单管理器勾选摄像头权限. 首先右键项目引用,打开Nuget包管理器搜索安装:ZXing.Net.Mobi ...