UVA-806 Spatial Structures (四分树)
题目大意:将一块图像上的黑点在两种表示法之间转换。
题目分析:递归下去。。。
注意:输出时要注意细节!!!
代码如下:
# include<iostream>
# include<cstdio>
# include<vector>
# include<string>
# include<cstring>
# include<algorithm>
using namespace std; char p[80][80];
int ans;
vector<int>v; int get(int r,int c,int w)
{
int cnt=0;
for(int i=r;i<r+w;++i)
for(int j=c;j<c+w;++j)
if(p[i][j]=='1')
++cnt;
return cnt;
} int getVal(string path)
{
int l=path.size();
int res=0;
for(int i=l-1;i>=0;--i)
res=res*5+path[i]-'0';
return res;
} ///查看以(r,c)为左上角,边长为w的子正方形。下同。
void f1(int r,int c,int w,string path)
{
int k=get(r,c,w);
if(k==0)
return ;
if(k==w*w){
++ans;
v.push_back(getVal(path));
return ;
}
f1(r,c,w/2,path+'1');
f1(r,c+w/2,w/2,path+'2');
f1(r+w/2,c,w/2,path+'3');
f1(r+w/2,c+w/2,w/2,path+'4');
} void f2(int r,int c,int w,int s)
{
if(s==0){
for(int i=r;i<r+w;++i)
for(int j=c;j<c+w;++j)
p[i][j]='*';
return ;
}
int mod=s%5;
if(mod==1)
f2(r,c,w/2,s/5);
else if(mod==2)
f2(r,c+w/2,w/2,s/5);
else if(mod==3)
f2(r+w/2,c,w/2,s/5);
else if(mod==4)
f2(r+w/2,c+w/2,w/2,s/5);
} int main()
{
//freopen("UVA-806 Spatial Structures.txt","r",stdin);
int n,cas=0,flag=0;
while(scanf("%d",&n)&&n)
{
v.clear();
if(flag)
printf("\n");
flag=1;
if(n>0){
for(int i=0;i<n;++i)
scanf("%s",p[i]);
printf("Image %d\n",++cas);
ans=0;
f1(0,0,n,"");
sort(v.begin(),v.end());
int l=v.size();
for(int i=0;i<l;++i)
printf("%d%c",v[i],(i%12==11||i==l-1)?'\n':' ');
printf("Total number of black nodes = %d\n",ans);
}
if(n<0){
n=-n;
for(int i=0;i<n;++i){
for(int j=0;j<n;++j)
p[i][j]='.';
p[i][n]=0;
}
int a;
while(scanf("%d",&a)&&a!=-1)
v.push_back(a);
printf("Image %d\n",++cas);
int l=v.size();
for(int i=0;i<l;++i)
f2(0,0,n,v[i]);
for(int i=0;i<n;++i)
puts(p[i]);
}
}
return 0;
}
UVA-806 Spatial Structures (四分树)的更多相关文章
- UVA 806 Spatial Structures
题意: 如果某一大区域所有色块颜色是相同的,那么这一个大区域就算作一块,如果不同,则将其划分成四个小区域,然后重复上述步骤递归进行直到所有区域的颜色相同为止.然后根据上面划分的区域建树,小区域作为大区 ...
- UVA806-Spatial Structures(四分树)
Problem UVA806-Spatial Structures Accept:329 Submit:2778 Time Limit: 3000 mSec Problem Description ...
- UVA - 297 Quadtrees (四分树)
题意:求两棵四分树合并之后黑色像素的个数. 分析:边建树边统计. #include<cstdio> #include<cstring> #include<cstdlib& ...
- UVa 806 四分树
题意: 分析: 类似UVa 297, 模拟四分树四分的过程, 就是记录一个左上角, 记录宽度wideth, 然后每次w/2这样递归下去. 注意全黑是输出0, 不是输出1234. #include &l ...
- UVA.297 Quadtrees (四分树 DFS)
UVA.297 Quadtrees (四分树 DFS) 题意分析 将一个正方形像素分成4个小的正方形,接着根据字符序列来判断是否继续分成小的正方形表示像素块.字符表示规则是: p表示这个像素块继续分解 ...
- UVa 297 (四分树 递归) Quadtrees
题意: 有一个32×32像素的黑白图片,用四分树来表示.树的四个节点从左到右分别对应右上.左上.左下.右下的四个小正方区域.然后用递归的形式给出一个字符串代表一个图像,f(full)代表该节点是黑色的 ...
- 四分树 (Quadtrees UVA - 297)
题目描述: 原题:https://vjudge.net/problem/UVA-297 题目思路: 1.依旧是一波DFS建树 //矩阵实现 2.建树过程用1.0来填充表示像素 #include < ...
- uva806 Spatial Structures 空间结构 (黑白图像的四分树表示)
input 8 00000000 00000000 00001111 00001111 00011111 00111111 00111100 00111000 -8 9 14 17 22 23 44 ...
- 搜索(四分树):BZOJ 4513 [SDOI2016 Round1] 储能表
4513: [Sdoi2016]储能表 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 395 Solved: 213[Submit][Status] ...
随机推荐
- 南京网络赛G-Lpl and Energy【线段树】
During tea-drinking, princess, amongst other things, asked why has such a good-natured and cute Drag ...
- SpringBoot使用SpringSecurity搭建基于非对称加密的JWT及前后端分离的搭建
SpringBoot使用SpringSecurity搭建基于非对称加密的JWT及前后端分离的搭建 - lhc0512的博客 - CSDN博客 https://blog.csdn.net/lhc0512 ...
- Why Choose Jetty?
https://webtide.com/why-choose-jetty/ Why Choose Jetty? The leading open source app server availab ...
- TA-Lib中文文档(二):talib安装
安装 使用pip安装 PyPI: $ pip install TA-Lib Or checkout the sources and run setup.py yourself: $ python se ...
- Flask知识总汇
Flask基础 Flask基础使用与配置 Flask路由系统与模板系统 Flask视图函数 Flask请求与响应 Flask的session操作 Flask中间件 Flask连接数据库 Flask使用 ...
- scRNA-seq测序的两种技术[转载]
转自:http://www.ebiotrade.com/newsf/2017-9/201795172237350.htm 1.综述 哈佛大学的两个团队将微流体技术引入单细胞RNA-Seq方法中,分别开 ...
- Z-score标准化[转载]
转自:https://blog.csdn.net/Orange_Spotty_Cat/article/details/80312154 1.意义 Z-Score通过(x-μ)/σ将两组或多组数据转化为 ...
- java基础知识 构造方法
在java里面,构造方法也就是构造函数 构造函数=构造方法;构造方法是一种特殊的方法,具有以下特点.(1)构造方法的方法名必须与类名相同.(2)构造方法没有返回类型,也不能定义为void,在方法名前面 ...
- Rails的HashWithIndifferentAccess
ruby 2.0 引入了keyword arguments,方法的参数可以这么声明 def foo(bar: 'default') puts bar end foo # => 'default' ...
- hdu 5017
好恶心的题 #include <cstdio> #include <string.h> #include <algorithm> #include <cmat ...