zoukankan      html  css  js  c++  java
  • POJ2083 Fractal

    题意

    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.

    分析

    照题意模拟即可,分形题递归很好写。

    我输出来看了下,的确很震撼。
    POJ2803.out
    做这题的意义不在于AC。

    代码

    #include<iostream>
    #define rg register
    #define il inline
    #define co const
    template<class T>il T read(){
    	rg T data=0,w=1;
    	rg char ch=getchar();
    	while(!isdigit(ch)){
    		if(ch=='-') w=-1;
    		ch=getchar();
    	}
    	while(isdigit(ch))
    		data=data*10+ch-'0',ch=getchar();
    	return data*w;
    }
    template<class T>il T read(rg T&x){
    	return x=read<T>();
    }
    typedef long long ll;
    using namespace std;
    co int p[7]={1,3,9,27,81,243,729};
    char s[730][730];
    void draw(int x,int y,int n){
    	if(n==0){
    		s[x][y]='X';
    		return;
    	}
    	draw(x,y,n-1);
    	draw(x,y+2*p[n-1],n-1);
    	draw(x+p[n-1],y+p[n-1],n-1);
    	draw(x+2*p[n-1],y,n-1);
    	draw(x+2*p[n-1],y+2*p[n-1],n-1);
    }
    void print(int n){
    	for(int i=1;i<=p[n];++i){
    		for(int j=1;j<=p[n];++j)
    			putchar(s[i][j]);
    		puts("");
    	}
    	puts("-");
    }
    int main(){
    //	freopen("POJ2803.in","r",stdin);
    //	freopen("POJ2803.out","w",stdout);
    	for(int i=1;i<=729;++i)
    		for(int j=1;j<=729;++j)
    			s[i][j]=' ';
    	draw(1,1,6);
    	int n;
    	while(~scanf("%d",&n)&&~n)
    		print(n-1);
    	return 0;
    }
    
  • 相关阅读:
    让人耗尽脑汁的需求分析工作
    解读ASP.NET 5 & MVC6系列(1):ASP.NET 5简介
    WCF序列化与反序列化问题
    SQL存储过程调试
    MSSQL CharIndex()用法
    Erp:原料投入产出报表
    union all 简单用法
    带有游标的应用的存储过程
    SQL批量删除与批量插入
    表与表 不同条件下的关联SQL
  • 原文地址:https://www.cnblogs.com/autoint/p/10391592.html
Copyright © 2011-2022 走看看