软件工程

本类阅读TOP10

·PHP4 + MYSQL + APACHE 在 WIN 系统下的安装、配置
·Linux 入门常用命令(1)
·Linux 入门常用命令(2)
·使用 DCPROMO/FORCEREMOVAL 命令强制将 Active Directory 域控制器降级
·DirectShow学习(八): CBaseRender类及相应Pin类的源代码分析
·基于ICE方式SIP信令穿透Symmetric NAT技术研究
·Windows 2003网络负载均衡的实现
·一网打尽Win十四种系统故障解决方法
·数百种 Windows 软件的免费替代品列表
·收藏---行百里半九十

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
JOJ-2165-Hilbert Curve

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站


The pictures above are Hilbert curve.You can see a Hilbert curve with a certain recursion depth n is composed of four different Hilbert curves with a certain recursion depth n-1 and three segments.

For this problem, you are to output the Hilbert Curve up to a certain recursion depth, using just 'X'.Draw the smallest Hilbert curve (that is not divided any further) as follows:

XXX
X
XXX
To see how to draw larger Hilbert curve, take a look at the sample output.

Input

The input contains several testcases. Each is specified by an integer n (1 < n < 9).

Output

For each test case, output the Hilbert curve with the certain recursion depth n.The output must not contain any trailing blanks. Print an empty line after each test case.

Sample Input

2
3

Sample Output

XXXXX X
X   X X
XXX XXX
  X
XXX XXX
X   X X
XXXXX X

XXXXX XXXXX XXX
X   X X   X X
XXX XXX XXX XXX
  X     X     X
XXX XXX X XXX X
X   X X X X X X
XXXXX X XXX XXX
      X
XXXXX X XXX XXX
X   X X X X X X
XXX XXX X XXX X
  X     X     X
XXX XXX XXX XXX
X   X X   X X
XXXXX XXXXX XXX





#include<iostream> using namespace std; void main() { int lines[9]; lines[0]=1; for(int i=1;i<9;i++) lines[i]=lines[i-1]*2+1; char Hilbert[520][520]; Hilbert[0][0]='X'; int r=1; for(int i=1;i<9;i++) { for(int j=0;j<r;j++) for(int k=0;k<r;k++) { Hilbert[j][r+1+k]=Hilbert[k][r-1-j]; Hilbert[r+1+j][k]=Hilbert[j][k]; Hilbert[r+1+j][r+1+k]=Hilbert[r-1-k][j]; } Hilbert[0][r]='X'; Hilbert[r][r-1]='X'; Hilbert[2*r][r]='X'; r=r*2+1; } int n; while(cin>>n) { for(int i=0;i<lines[n];i++) { int len=lines[n]-1; while(Hilbert[i][len]!='X') len--; for(int j=0;j<=len;j++) if(Hilbert[i][j]=='X') cout<<Hilbert[i][j]; else cout<<' '; cout<<endl; } cout<<endl; } }
 
 
 
没有对数组进行初始化,如果全部先赋为空格反而会费时间 在打印时判断更好



相关文章

相关软件