编程介的小学生 2019-10-04 21:57 采纳率: 20.5%
浏览 184

The Sierpinski Fractal 三角形问题

Description

Consider a regular triangular area, divide it into four equal triangles of half height and remove the one in the middle. Apply the same operation recursively to each of the three remaining triangles. If we repeated this procedure infinite times, we'd obtain something with an area of zero. The fractal that evolves this way is called the Sierpinski Triangle. Although its topological dimension is 2, its Hausdorff-Besicovitch dimension is log(3)/log(2)~1.58, a fractional value (that's why it is called a fractal). By the way, the Hausdorff-Besicovitch dimension of the Norwegian coast is approximately 1.52, its topological dimension being 1.

For this problem, you are to outline the Sierpinski Triangle up to a certain recursion depth, using just ASCII characters. Since the drawing resolution is thus fixed, you'll need to grow the picture appropriately. Draw the smallest triangle (that is not divided any further) with two slashes, to backslashes and two underscores like this:
/\

/__\

To see how to draw larger triangles, take a look at the sample output.
Input

The input contains several testcases. Each is specified by an integer n. Input is terminated by n=0. Otherwise 1<=n<=10 indicates the recursion depth.
Output

For each test case draw an outline of the Sierpinski Triangle with a side's total length of 2n characters. Align your output to the left, that is, print the bottom leftmost slash into the first column. The output must not contain any trailing blanks. Print an empty line after each test case.
Sample Input

3
2
1
0
Sample Output

   /\
  /__\
 /\  /\
/__\/__\

/\ /\
/__\ /__\
/\ /\ /\ /\
/__\/__\/__\/__\

/\
/__\
/\ /\
/__\/__\

/\
/__\

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 stm32流水灯+呼吸灯+外部中断按键
    • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符
    • ¥15 NX MCD仿真与博途通讯不了啥情况
    • ¥15 win11家庭中文版安装docker遇到Hyper-V启用失败解决办法整理
    • ¥15 gradio的web端页面格式不对的问题
    • ¥15 求大家看看Nonce如何配置
    • ¥15 Matlab怎么求解含参的二重积分?
    • ¥15 苹果手机突然连不上wifi了?
    • ¥15 cgictest.cgi文件无法访问
    • ¥20 删除和修改功能无法调用