Spacial Structures Uva806
//Spatial Structures
//My Solution. Yhq
#include<iostream>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#define maxn 1<<9
using namespace std;
char pic[maxn][maxn];
int size;
vector<int> vec[maxn];
vector<int> tree;
int vec_cnt=0;
void reset() {tree.clear();vec_cnt=0;memset(pic,'.',sizeof(pic));for (int i=0; i<maxn; ++i) vec[i].clear();
}
void trans(int n) {while (n>0) {int p=n%5;n=n/5;vec[vec_cnt].push_back(p);}vec_cnt++;
}
void to_pic_dfs(int cnt, int row, int col, int sz, int dep) {if (dep==vec[cnt].size()) {for (int i=row; i<row+sz; ++i)for (int j=col; j<col+sz; ++j)pic[i][j]='*';return;}switch (vec[cnt][dep]) {case 1:to_pic_dfs(cnt, row, col, sz/2, dep+1);break;case 2:to_pic_dfs(cnt, row, col+sz/2, sz/2, dep+1);break;case 3:to_pic_dfs(cnt, row+sz/2, col, sz/2, dep+1);break;case 4:to_pic_dfs(cnt, row+sz/2, col+sz/2, sz/2, dep+1);break;}
}
void to_pic() {for (int i=0; i<vec_cnt; ++i) to_pic_dfs(i, 0, 0, size, 0);
}
void print_pic() {for (int i=0; i<size; ++i)for (int j=0; j<size; ++j) {cout<<pic[i][j];if (j==size-1) cout<<endl;}
}
bool isfull (int row, int col, int sz) {for (int i=row; i<row+sz; ++i)for (int j=col; j<col+sz; ++j)if (pic[i][j]=='.') return false;return true;
}
void to_tree_dfs (int row, int col, int sz, int step, int tmp) {if (sz/2==0) return;if (isfull(row,col,sz/2)) {tree.push_back(tmp+pow(5,step)*1);} else {to_tree_dfs(row, col, sz/2, step+1, tmp+pow(5,step)*1);}if (isfull(row,col+sz/2,sz/2)) {tree.push_back(tmp+pow(5,step)*2);} else {to_tree_dfs(row, col+sz/2, sz/2, step+1, tmp+pow(5,step)*2);}if (isfull(row+sz/2,col,sz/2)) {tree.push_back(tmp+pow(5,step)*3);} else {to_tree_dfs(row+sz/2, col, sz/2, step+1, tmp+pow(5,step)*3);}if (isfull(row+sz/2,col+sz/2,sz/2)) {tree.push_back(tmp+pow(5,step)*4);} else {to_tree_dfs(row+sz/2, col+sz/2, sz/2, step+1, tmp+pow(5,step)*4);}
}
void print_tree() {sort(tree.begin(), tree.end());if (tree.empty()) cout<<"Total number of black nodes = 0"<<endl;else {for (int i=0; i<tree.size(); ++i) {cout<<tree[i];if (i<tree.size()-1) cout<<" ";else cout<<endl;}}
}
int main () {int counter=0;while(cin>>size) {if (size==0) return 0;counter++;cout<<"Image "<<counter<<endl;reset();if (size<0) {size=-size;int num;while (cin>>num) {if (num==-1) break;if (num==0) {for (int i=0; i<size; ++i)for (int j=0; j<size; ++j)pic[i][j]='*';} else trans(num); //转换成“路径表示序列 ”存入vector[vec_cnt]}to_pic();print_pic();} else {char ch;for (int i=0; i<size; ++i)for (int j=0; j<size; ++j) {cin>>ch;if (ch=='1') pic[i][j]='*';}if (isfull(0,0,size)) tree.push_back(0);else to_tree_dfs(0, 0, size, 0, 0);print_tree();}cout<<endl;}return 0;
}
Spacial Structures Uva806相关推荐
- UVA-806 Spatial Structures (四分树)
题目大意:将一块图像上的黑点在两种表示法之间转换. 题目分析:递归下去... 注意:输出时要注意细节!!! 代码如下: # include<iostream> # include<c ...
- pandas笔记(pandas Data Structures)
pandas笔记(pandas Data Structures) 生信start_site已关注 32020.06.15 03:02:37字数 766阅读 509 pandas包含数据结构和数据操作工 ...
- python 科学计算设计_Python科学计算——Data Structures
为什么选择Python作为科学计算语言? 有关于Matlab和Python哪个更适合作为科学计算语言的争论已久,之所以选择Python作为首选的科学计算语言,不仅仅是因为它免费,开源,有很多优秀的库和 ...
- Data Structures with C++ Using STL Chapter 3算法概述---笔记
<Data Structures with C++ Using STL Chapter 3算法概述---笔记>,作者:茉莉花茶,原文链接:http://www.cnblogs.com/yc ...
- 【Android 逆向】IDA 工具使用 ( 十六进制视图 Hex View-1 | 结构体视图 Structures | 枚举视图 Enums | 导入视图 Import | 导出视图 )
文章目录 一.十六进制视图 Hex View-1 二.结构体视图 Structures 三.枚举视图 Enums 四.导入视图 Import 五.导出视图 Export 一.十六进制视图 Hex Vi ...
- Instance and Media Recovery Structures
Server process : 独立的 server, shared server. 以上结构中:真正存放在磁盘上的物理文件是图的下半部分,那么它们具体存放在哪里的,一般来讲: contrl fil ...
- 板材开料最优算法_板材套料软件AutoNest与Tekla Structures协同工作实现设计到加工自动化...
板材套料软件AutoNEST与Tekla Structures协同工作实现设计到加工自动化 摘要: 企业应该开始考虑 Tekla Structures 软件如何能应用到其他的部门以及其他的项目生产流程 ...
- 数据结构(Data structures)(二):结构体指针
Pointers to structures 像其它数据类型一样,结构体也可以有指针.可以被它自己的类型的指针所指向.其规则同其它基本数据类型一样: struct movies_t{ string t ...
- mybatis 配置错误 XML document structures must start and end within the same entity
JAVA就业套餐课:https://edu.csdn.net/combo/detail/1230 问题如下: Exception in thread "main" org.apac ...
最新文章
- 使用Zabbix通过BMC管理口监控HP服务器
- Alphabet wars - nuclear strike--5 kyu--Python解法
- 后台ajax调用中字符串到jquery中的json对象和数组对象转换问题
- shell中exec解析
- 深入理解JVM—性能监控工具
- 云服务器 存放 文件夹,云服务器 存放 文件夹
- intellij idea开发工具
- RestTemplate实践(及遇到的问题)
- OpenCV 20 年,首款开源软硬一体的 OAK 套件来了!
- Netty源码解读(一)概述
- 微信公众号调用扫一扫,使扫一扫支持扫PDF417格式的条码
- 怎么进计算机更新失败,系统更新失败无法进入系统怎么办?
- WordPress添加站点图标与底部备案信息
- 标签助手(TagHelper)
- 加密解密(8)申请证书相关知识
- CT图像的窗宽窗位(VTK及3Dslicer中的使用)
- 可以弹奏的钢琴页面(HTML实现)
- Django报错 ValueError: The view didn‘t return an HttpResponse object. It returned None instead.
- 爱情大数据 | 你的专属微信聊天记录统计
- 七巧板复原之剩余区域的计算-多边形的加减法计算
热门文章
- java soap 解析,java 解析soap
- CATIA CAA二次开发专题(九)---3DE平台的特征树遍历
- linux静态反汇编工具,27款反汇编/调试器/静态和动态分析工具
- 简要解析Java中的throw和throws关键字
- Linux之httpd及虚拟主机的配置及使用
- 突发!Log4j 爆“核弹级”漏洞,Flink 等项目受影响,提供 Flink 解决方法,赶紧修!...
- 分享一组制作游戏用的人物立绘/角色形象素材图片,共337张图片
- 张一鸣和黄峥,为什么厉害?顶级高手都具备的四种思维模型
- Evince 0.7
- 金九银十已过,复盘阿里巴巴最全399道面试题以及答案