设为首页 加入收藏

TOP

有趣的分形图形-递归和数学方法解决-POJ 2083
2014-11-23 17:55:25 来源: 作者: 【 】 浏览:8
Tags:有趣 分形 图形 数学 方法 解决 -POJ 2083

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
-1Sample 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


一递归:
先看下较为常规的递归解决:

由于图形是重复的,小的图形只是把大图形的左上角一部分输出,,只计算最大的图形,打表可加快速度。

#include 
#include 
int p[8] = {1,3,9,27,81,243,729};
char map[730][730];
//n当前的图形大小,x,y图形所在的坐标
void print(int n,int x,int y){
	if(n == 0){
		map[x][y] = 'X'; //
		return;
	}
	print(n-1, x, y); //左上
	print(n-1, x+2*p[n-1], y); //右上
	print(n-1, x+p[n-1], y+p[n-1]); //中间
	print(n-1, x, y+2*p[n-1]);
	print(n-1, x+2*p[n-1],  y+2*p[n-1]);
}
int n;
int main(){
	for(int i=0; i= 0){
		for(int i=0; i 
 

二 数学方法

在discuss里面看到这个短小精悍的程序。

#include"stdio.h"
#include"math.h"
main()
{
	int i,j,n,ii,jj,k;
	while(scanf("%d",&n)&&n--!=-1)
	{
		for(i=0;i 
 

关于这个图形,还可以用来证明

寻找1/5 + 1/25 + 1/125 + .. = 1/4的图形证明


\

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇设计模式-单例模式 下一篇(step3.3) hdu 1059(Dividing――..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·09-指 针 (一)-c语言 (2025-12-26 10:20:58)
·About - Redis (2025-12-26 08:20:56)
·Redis: A Comprehens (2025-12-26 08:20:53)
·Redis - The Real-ti (2025-12-26 08:20:50)
·Bash 脚本教程——Li (2025-12-26 07:53:35)