【链接】 我是链接,点我呀:)

【题意】

在这里输入题意

【题解】

写两个dfs模拟就好。
注意每12个数字输出一个换行。。

【代码】

/*
1.Shoud it use long long ?
2.Have you ever test several sample(at least therr) yourself?
3.Can you promise that the solution is right? At least,the main ideal
4.use the puts("") or putchar() or printf and such things?
5.init the used array or any value?
6.use error MAX_VALUE?
7.use scanf instead of cin/cout?
*/
#include <bits/stdc++.h>
using namespace std; const int N = 100; int n;
char s[N][N];
vector <long long> v; int numberblack(int x1,int y1,int x2,int y2){
int cnt = 0;
for (int i = x1;i <= x2;i++)
for (int j = y1;j<= y2;j++)
if (s[i][j]=='1')
cnt++;
return cnt;
} void dfs(int x1,int y1,int x2,int y2,int now,int xishu){
int temp1 = numberblack(x1,y1,x2,y2);
if (temp1==0) return;
int should = (x2-x1+1)*(y2-y1+1);
if (temp1==should){
v.push_back(now);
return;
}
int midx = (x1+x2)/2,midy = (y1+y2)/2;
dfs(x1,y1,midx,midy,now + 1*xishu,xishu*5);
dfs(x1,midy+1,midx,y2,now + 2*xishu,xishu*5);
dfs(midx+1,y1,x2,midy,now + 3*xishu,xishu*5);
dfs(midx+1,midy+1,x2,y2,now + 4*xishu,xishu*5);
} void fugai(int x1,int y1,int x2,int y2){
for (int i = x1;i <= x2;i++)
for (int j = y1;j <= y2;j++)
s[i][j] = '*';
} void dfs2(int x1,int y1,int x2,int y2,int rest){
if (rest==0){
fugai(x1,y1,x2,y2);
return;
}
int ope = rest%5; int midx = (x1+x2)/2,midy = (y1+y2)/2;
switch (ope){
case 1: dfs2(x1,y1,midx,midy,rest/5);break;
case 2: dfs2(x1,midy+1,midx,y2,rest/5);break;
case 3: dfs2(midx+1,y1,x2,midy,rest/5);break;
case 4: dfs2(midx+1,midy+1,x2,y2,rest/5);break;
}
} int main(){
#ifdef LOCAL_DEFINE
freopen("F:\\c++source\\rush_in.txt", "r", stdin);
freopen("F:\\c++source\\rush_out.txt", "w", stdout);
#endif
ios::sync_with_stdio(0),cin.tie(0);
int kase = 0;
while (cin >>n && n!=0){
if (kase>0) cout << endl;
kase++;
cout <<"Image "<<kase<<endl;
if (n>0){
v.clear();
for (int i = 1;i <= n;i++) cin >> (s[i]+1);
dfs(1,1,n,n,0,1);
sort(v.begin(),v.end());
for (int i = 0;i < (int) v.size();i++){
cout << v[i];
if ((i+1)%12==0 || i==(int) v.size()-1) cout << endl;else cout <<' ';
}
cout <<"Total number of black nodes = "<<(int) v.size()<<endl;
}else{
n = -n;
for (int i = 1;i <= n;i++)
for (int j =1 ;j <= n;j++) s[i][j] = '.';
int x;
for (cin >>x;x!=-1;cin>>x){
dfs2(1,1,n,n,x);
} for (int i = 1;i <= n;i++){
for (int j =1 ;j <= n;j++) cout <<s[i][j];
cout << endl;
}
}
}
return 0;
}

【习题 6-8 UVA - 806】Spatial Structures的更多相关文章

  1. UVA 806 Spatial Structures

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

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

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

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

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

  4. UVa 806 四分树

    题意: 分析: 类似UVa 297, 模拟四分树四分的过程, 就是记录一个左上角, 记录宽度wideth, 然后每次w/2这样递归下去. 注意全黑是输出0, 不是输出1234. #include &l ...

  5. uva806 Spatial Structures 空间结构 (黑白图像的四分树表示)

    input 8 00000000 00000000 00001111 00001111 00011111 00111111 00111100 00111000 -8 9 14 17 22 23 44 ...

  6. ACM训练计划建议(写给本校acmer,欢迎围观和指正)

    ACM训练计划建议 From:freecode#  Date:2015/5/20 前言: 老师要我们整理一份训练计划给下一届的学弟学妹们,整理出来了,费了不少笔墨,就也将它放到博客园上供大家参考. 菜 ...

  7. ACM训练计划建议(转)

    ACM训练计划建议 From:freecode#  Date:2015/5/20 前言: 老师要我们整理一份训练计划给下一届的学弟学妹们,整理出来了,费了不少笔墨,就也将它放到博客园上供大家参考. 菜 ...

  8. 动态规划 Dynamic Programming 学习笔记

    文章以 CC-BY-SA 方式共享,此说明高于本站内其他说明. 本文尚未完工,但内容足够丰富,故提前发布. 内容包含大量 \(\LaTeX\) 公式,渲染可能需要一些时间,请耐心等待渲染(约 5s). ...

  9. UVa第五章STL应用 习题((解题报告))具体!

    例题5--9 数据库 Database UVa 1592 #include<iostream> #include<stdio.h> #include<string.h&g ...

随机推荐

  1. 在navicat中如何新建连接数据库

    前几天给大家分享了如何安装Navicat,没有来得及上车的小伙伴可以戳这篇文章:手把手教你安装Navicat——靠谱的Navicat安装教程.今天给大家分享一下Navicat的简单使用教程,具体的教程 ...

  2. ping 原理及ICMP协议简介

    //Ping IP/域名 public static String pingIPCennect(String ipStr) {  String result = "";  if ( ...

  3. WebAssembly学习(三):AssemblyScript - TypeScript到WebAssembly的编译

    虽然说只要高级语言能转换成 LLVM IR,就能被编译成 WebAssembly 字节码,官方也推荐c/c++的方式,但是让一个前端工程师去熟练使用c/c++显然是有点困难,那么TypeScript ...

  4. CentOS7 PXE安装批量安装操作系统

    1.安装相关软件 yum -y install tftp-server httpd dhcp syslinux 2.配置DHCP cp /usr/share/doc/dhcp-4.2.5/dhcpd. ...

  5. ios in-house 公布整个过程(startssl认证)

    首先大体说一下步骤: 1.申请苹果enterprise 账号 为应用生成app id,provision profile等 详见:http://www.th7.cn/Program/IOS/20131 ...

  6. 验证list的底层数据结构

    <STL源代码剖析>中,指出SGI STL的list底层数据结构式循环双向链表.而且在链表尾端留一个空白节点.让end指向它.因为是双向的,那么list的迭代器必须是Bidirection ...

  7. pix格式的摸索(二)

    作者:朱金灿 来源:http://blog.csdn.net/clever101 PCI的系统格式pix是一个设计很巧妙的遥感图像格式,而且其设计巧妙之处不止一处两处,这些都有待我日后一一去摸索.今天 ...

  8. Domino系统从UNIX平台到windows平台的迁移及备份

    单位机房的一台服务机器到折旧期了,换成了新购IBM机器X3950,而且都预装了windows 2003 server 标准版,所以只有把以前在Unix平台下跑的OA系统迁移到新的windows 200 ...

  9. Self-Taught Learning to Deep Networks

    In this section, we describe how you can fine-tune and further improve the learned features using la ...

  10. 洛谷——P1137 旅行计划

    https://www.luogu.org/problem/show?pid=1137 题目描述 小明要去一个国家旅游.这个国家有N个城市,编号为1-N,并且有M条道路连接着,小明准备从其中一个城市出 ...