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;
}

posted on 2019-02-17 16:18  autoint  阅读(268)  评论(0编辑  收藏  举报

导航