1085:Fractal(分治法)
来源:互联网 发布:幻想武器知乎 编辑:程序博客网 时间:2024/06/05 04:40
1085:Fractal
- 查看
- 提交
- 统计
- 提问
- 时间限制:
- 1000ms
-
- 内存限制:
- 65536kB
- 描述
- A fractal is an object or quantity that displays self-similarity,in a somewhat technical sense, on all scales. The object need notexhibit 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
XX
X
XX - If using B(n - 1) to represent the box fractal of degree n - 1,then a box fractal of degree n is defined recursively asfollowing
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. - A box fractal of degree 1 is simply
- 输入
- The input consists of several test cases. Each line of the inputcontains a positive integer n which is no greater than 7. The lastline of input is a negative integer −1 indicating the end ofinput.
- 输出
- For each test case, output the box fractal using the 'X' notation.Please notice that 'X' is an uppercase letter. Print a line withonly a single dash after each test case.
- 实验源码(OpenJudge提交通过)
#include <stdio.h>
char box[730][730]={"",""};
void drawFractalBox(int n,int x,int y)//x为行,y为列
{
int i=n;
int c=1;
while(--i)
c=c*3;
//首先计算打印的行数和列数 C
if(c==1)
{
box[x][y]='X';
return;
}
else
{
drawFractalBox(n-1,x,y); //左上
drawFractalBox(n-1,x,(c*2)/3+y); //右上
drawFractalBox(n-1,c/3+x,c/3+y); //中间
drawFractalBox(n-1,(c*2)/3+x,y); //左下
drawFractalBox(n-1,(2*c)/3+x,y+(2*c)/3); //右下
}
}
int main()
{
int i,j,n;
scanf("%d",&n);
while(n!=-1)
{
int num=1;
int t=n;
while(--t)
num=num*3; //得到行列数
for(i=1;i<=num;i++)
for(j=1;j<=num;j++)
box[i][j]=' '; //初始化
drawFractalBox(n,1,1); //填充
for(i=1;i<=num;i++)
{
for(j=1;j<=num;j++)
printf("%c",box[i][j]);
printf("\n");
}//输出
printf("-\n");
scanf("%d",&n);//输入下一个
}
return 0;
}
运行结果截图:
- 1085:Fractal(分治法)
- POJ2083 Fractal (分治法)
- POJ 题目2083 Fractal(分治)
- POJ 2083 Fractal 分治+递归
- POJ 2083 Fractal (分形&分治)
- hiho1234--Fractal(高精度)
- 分形图(fractal pictures)
- Fractal (分形)
- Fractal
- Fractal
- Fractal
- POJ—2083—Fractal—【递归与分治】
- POJ 2083 Fractal(递归)
- POJ 2083 Fractal(dfs)
- poj3845:Fractal(坐标旋转)
- 分治法(浅谈分治法)
- 幂取模 (分治法)
- (四)分治法
- 动态不等长存储资源分配算法
- Java线程池使用
- 文件系统——Hash结构文件
- 2684:求阶乘的和(一个高效的算法C…
- 回溯搜索166:The Castle(OpenJudge…
- 1085:Fractal(分治法)
- 4004:数字组合||子集和数
- 1017:装箱问题(贪心)
- 括号匹配问题
- 165:The Triangle(动态规划)
- glViewport()函数和glOrtho()函数的理解
- Runtime Error问题
- 02:螺旋矩阵
- 03:约瑟夫环问题(数组解决)