input

8
00000000
00000000
00001111
00001111
00011111
00111111
00111100
00111000
-8
9 14 17 22 23 44 63 69 88 94 113 -1
2
00
00
-4
0 -1
0

output

Image 1
9 14 17 22 23 44 63 69 88 94 113
Total number of black nodes = 11 Image 2
........
........
....****
....****
...*****
..******
..****..
..***... Image 3
Total number of black nodes = 0 Image 4
****
****
****
**** 这题目就是给你黑白点图的两种表示方法让你互相转化,写的时候没注意格式。
数字是代表四分树黑色结点到根的距离,由于定义是递归的,所以不必真的把树建出来。


/*
Created by Rey Chen on 2015.6.30
Copyright (c) 2015 Rey . All rights reserved.
*/ #include<cstdio>
#include<algorithm>
using namespace std;
const int maxn = ; char G[maxn][maxn]; int path[maxn*maxn];
int sz; void solve1(int r1,int c1,int r2,int c2,int wei,int sum)
{
bool whi, bla; whi = bla = false;
for(int i = r1;i <= r2;i++)
for(int j = c1;j <= c2;j++){
if(!bla && G[i][j] == '') bla = true;
if(!whi && G[i][j] == '') whi = true;
if(whi&&bla) { break;}
}
if(bla) {
if(!whi) {path[++sz] = sum; return;}
}else if(whi) return; int dvr = r1+r2>>, dvc = c1+c2>>;
int nwei = *wei;
solve1( r1, c1,dvr,dvc,nwei,sum+ wei );
solve1( r1,dvc+,dvr, c2,nwei,sum+(wei<<));
solve1(dvr+, c1 ,r2,dvc,nwei,sum+ wei* );
solve1(dvr+,dvc+, r2 ,c2,nwei,sum+(wei<<));
} int a[];
void draw(int n,int r1,int c1,int r2,int c2){
int Sz = ;
while(n){ a[Sz++]=n%;n/=;}
for(int i = ; i < Sz;i++){
switch (a[i]){
case :{
r2 = r1+r2>>; c2 = c1+c2>>;
break;
}
case :{
r2 = r1+r2>>; c1 = (c1+c2>>)+;
break;
}
case :{
r1 = (r1+r2>>)+; c2 = c1+c2>>;
break;
}
case :{
r1 = (r1+r2>>)+; c1 = (c1+c2>>)+;
break;
}
}
}
for(int i = r1;i <= r2;i++)
for(int j = c1;j <= c2;j++)
G[i][j] = '*';
} int main()
{
int n;
int Cas = ;
while(~scanf("%d",&n)&&n){
if(Cas) puts("");
if(n>){
for(int i = ; i < n; i++)
scanf("%s",G[i]);
sz = ;
solve1(,,n-,n-,,);
sort(path+,path+sz+); printf("Image %d\n",++Cas);
for(int i = ; i < sz; i++)//PE了。。。
printf("%d%c",path[i],i%?' ':'\n');
if(sz)printf("%d\n",path[sz]);
printf("Total number of black nodes = %d\n",sz);
}else {
n = -n;
int t;
for(int i = ;i < n;i++){
for(int j = ;j < n;j++)
G[i][j]='.';
G[i][n] = '\0';
} while(scanf("%d",&t)&&~t){
draw(t,,,n-,n-);
}
printf("Image %d\n",++Cas);
for(int i = ;i < n;i++)
puts(G[i]);
} }
return ;
}

uva806 Spatial Structures 空间结构 (黑白图像的四分树表示)的更多相关文章

  1. UVA-806 Spatial Structures (四分树)

    题目大意:将一块图像上的黑点在两种表示法之间转换. 题目分析:递归下去... 注意:输出时要注意细节!!! 代码如下: # include<iostream> # include<c ...

  2. [刷题]算法竞赛入门经典(第2版) 6-8/UVa806 - Spatial Structures

    题意:黑白图像的路径表示法 代码:(Accepted,0.120s) //UVa806 - Spatial Structures //Accepted 0.120s //#define _XIENAO ...

  3. [ActionScript 3.0] AS3.0 将图像的Alpha通道转换为黑白图像(分离ARGB方式)

    import flash.display.BitmapData; import flash.display.Bitmap; /** * 将图像的Alpha通道转换为黑白图像(分离ARGB方式) */ ...

  4. [ActionScript 3.0] AS3.0将图像的Alpha通道转换为黑白图像(复制通道方式)

    import flash.display.BitmapData; /** * 将图像的Alpha通道转换为黑白图像 */ var p:Point = new Point(0,0); var bmpd: ...

  5. 黑白图像(DFS)

    输入一个n*n的黑白图像(1表示黑色,0表示白色),任务是统计其中八连块的个数.如果两个黑格子有公共边或者公共顶点,就说它们属于同一个八连块.如图6-11所示的图形有3个八连块. 图6-11  拥有3 ...

  6. UVA 806 Spatial Structures

    题意: 如果某一大区域所有色块颜色是相同的,那么这一个大区域就算作一块,如果不同,则将其划分成四个小区域,然后重复上述步骤递归进行直到所有区域的颜色相同为止.然后根据上面划分的区域建树,小区域作为大区 ...

  7. TZOJ 3533 黑白图像(广搜)

    描述 输入一个n*n的黑白图像(1表示黑色,0表示白色),任务是统计其中八连块的个数.如果两个黑格子有公共边或者公共顶点,就说它们属于同一个八连块.如图所示的图形有3个八连块. 输入 第1行输入一个正 ...

  8. MATLAB读取黑白图像显示却是黑色,24位深转8位深黑白图像解决方法

    1.24位深转8位深: ps将24位深原图.png保存为GIF图256即为8位,再将8位gif图转为需要的.png,即转为8位深png图. 2.MATLAB读取黑白图像显示几乎全为黑色: 这是最近处理 ...

  9. 小白书 黑白图像【DFS/Flood Fill】

    http://blog.csdn.net/u010470972/article/details/33415617 Description 输入一个n×n的黑白图像(1表示黑色,0表示白色),任务是统计 ...

随机推荐

  1. zoj 3640 Help Me Escape (概率dp 递归求期望)

    题目链接 Help Me Escape Time Limit: 2 Seconds      Memory Limit: 32768 KB Background     If thou doest w ...

  2. Linux 之 .bashrc 文件作用

    Linux 系统中很多 shell,包括bash,sh,zsh,dash 和 korn 等,不管哪种 shell 都会有一个 .bashrc 的隐藏文件,它就相当于 shell 的配置文件. 一般会有 ...

  3. apply的使用技巧

    1.什么是apply?他和call有什么区别? apply:方法能劫持另外一个对象的方法,继承另外一个对象的属性. Function.apply(obj,args)方法能接收两个参数 obj:这个对象 ...

  4. HyperLedger Fabric 多机部署(二)

    启动各个节点: ./orderer order节点启动方式 ./peer node start peer节点启动方式 Admin@org1.example.com 使用hyperledger fabr ...

  5. HyperLedger Fabric 多机部署(一)

    本文参考:http://www.lijiaocn.com/%E9%A1%B9%E7%9B%AE/2018/04/26/hyperledger-fabric-deploy.html  学习. 1.准备工 ...

  6. web前端篇:CSS使用,样式表特征,选择器

    目录 web前端篇:CSS使用,样式表特征,选择器 1.CSS介绍 2.CSS使用 3.样式表特征 4.CSS选择器 5.选择器的优先级 6.练习题: web前端篇:CSS使用,样式表特征,选择器 1 ...

  7. 有关xerosploit运行报错问题的有效解决方案

    [安装xerosploit]安装xerosploit的步骤如下,我是将xerosploit直接克隆到了根目录下(使用“cd /”到达根目录) git clone https://github.com/ ...

  8. HttpServletRequest 和 HttpServletResponse

    Servlet配置方式 全路径匹配 以 / 开始 /a /aa/bb localhost:8080/项目名称/aa/bb 路径匹配 , 前半段匹配 以 / 开始 , 但是以 * 结束 /a/* /* ...

  9. Tkinter 的三大布局管理器 pack、grid 和 place用法汇总

    学习python的tkinter免不了要对各个组件进行位置的排放与设定,常用的布局管理器有grid,pack和place.这三种均用于同一父组件下的组件布局,但是也是有区别的,先看下他们各自的含义吧. ...

  10. 常见的HTTP状态码说明

    1.说明 HTTP服务器状态代码定义(Status Code Definitions) 做测试的时候,会产生比较多的HTTP错误,查看其错误,有超时的,链接不到图片的,连接不到服务器等等,很多人经常忘 ...