zoukankan      html  css  js  c++  java
  • sss

    Description

    A fractal is an object or quantity that displays self-similarity, in a somewhat technical sense, on all scales. The object need not

    exhibit exactly the same structure at all scales, but the same "type" of structures must appear on all scales.

    A box fractal is defined as below :

    A box fractal of degree 1 is simply

    X 
    

    A box fractal of degree 2 is

    X  X 
    
      X 
    
    X  X 
    

    If using B(n - 1) to represent the box fractal of degree n - 1, then a box fractal of degree n is defined recursively as following

    B(n - 1)        B(n - 1)
    
            B(n - 1)
    
    B(n - 1)        B(n - 1)
    

    Your task is to draw a box fractal of degree n.

    Input

    The input consists of several test cases. Each line of the input contains a positive integer n which is no greater than 7.

    The last line of input is a negative integer −1 indicating the end of input.

    Output

    For each test case, output the box fractal using the 'X' notation. Please notice that 'X' is an uppercase letter. Print a line

    with only a single dash after each test case.

    Sample Input

    1

    2

    3

    4

    -1

    Examples

    Input

    3

    2 3 2

    2

    3 2

    2 3

    Output

    X
    -
    X X
     X
    X X
    -
    X X   X X
     X     X
    X X   X X
       X X
        X
       X X
    X X   X X
     X     X
    X X   X X
    -
    X X   X X         X X   X X
     X     X           X     X
    X X   X X         X X   X X
       X X               X X
        X                 X
       X X               X X
    X X   X X         X X   X X
     X     X           X     X
    X X   X X         X X   X X
             X X   X X
              X     X
             X X   X X
                X X
                 X
                X X
             X X   X X
              X     X
             X X   X X
    X X   X X         X X   X X
     X     X           X     X
    X X   X X         X X   X X
       X X               X X
        X                 X
       X X               X X
    X X   X X         X X   X X
     X     X           X     X
    X X   X X         X X   X X
    -
    

    Analysis

    一句话题意:打印图形

    其实就是把删一个图形在右上、左下、右下分别复制粘贴一遍就OK了

    然而我居然习惯输出空格导致WA了3发。。。

    代码

    真的很水啦。。。

    #include<iostream>
    #include<algorithm>
    #include<cstdlib>
    #include<cstdio>
    #include<cstring>
    using namespace std;
    int n,cnt[100];
    char co[1000][1000];
    void copy(int k,int x,int y){
    	for(int j=1;j<=cnt[k-1];j++){
    		for(int l=cnt[k-1]*2+1;l<=cnt[k];l++){//右上 
    			co[j][l]=co[j][l-cnt[k-1]*2];
    		}
    	}
    	for(int j=cnt[k-1]+1;j<=cnt[k-1]*2;j++){//中间 
    		for(int l=cnt[k-1]+1;l<=cnt[k-1]*2;l++){
    			co[j][l]=co[j-cnt[k-1]][l-cnt[k-1]];
    		}
    	}
    	for(int j=cnt[k-1]*2+1;j<=cnt[k];j++){//左下 
    		for(int l=1;l<=cnt[k-1];l++){
    			co[j][l]=co[j-cnt[k-1]*2][l];
    		}
    	}
    	for(int j=cnt[k-1]*2+1;j<=cnt[k];j++){//右下 
    		for(int l=cnt[k-1]*2+1;l<=cnt[k];l++){
    			co[j][l]=co[j-cnt[k-1]*2][l-cnt[k-1]*2];
    		}
    	}
    }
    int main(){
    	cnt[0]=cnt[1]=1;
    	for(int i=2;i<=10;i++)cnt[i]=cnt[i-1]*3;
    	while(cin>>n){
    		memset(co,' ',sizeof(co));
    		if(n==-1)return 0;
    		co[1][1]='X';
    		for(int i=2;i<=n;i++){
    			copy(i,cnt[i],cnt[i]);
    		}
    		for(int i=1;i<=cnt[n];i++){
    			for(int j=1;j<=cnt[n];j++){
    				cout<<co[i][j];
    			}
    			cout<<endl;
    		}
    		cout<<"-"<<endl;
    	}
    }
    
  • 相关阅读:
    基于微软解决方案的负载测试实现知识库1____(转)理解.NET中的数据库连接池
    [转] Performance vs. load vs. stress testing _Grig Gheorghiu (翻译水平有限,如有错误请帮忙刊正)
    Bill Gates Centimillionaire and one poor man.
    VB Comwrapper 的实现
    使用接口作为返回值
    如何排查SQL死锁的错误?
    VC++动态链接库编程之DLL典型实例
    VC++动态链接库编程之DLL木马
    VC中获取窗口句柄的各种方法 .
    VC++动态链接库编程之MFC扩展 DLL
  • 原文地址:https://www.cnblogs.com/lqhsr/p/11265623.html
Copyright © 2011-2022 走看看