#5114. Sierpinski carpet

0
    ID: 5114 传统题 2000ms 1024MiB 尝试: 0 已通过: 0 难度: 2 上传者: 标签>AtCoderabc357CGESP 4级二维数组与矩阵DFS

Sierpinski carpet

Sierpinski carpet

题目描述

For a non-negative integer KK, we define a level-KK carpet as follows:

A level-00 carpet is a 1×11 \times 1 grid consisting of a single black cell. For K > 0, a level-KK carpet is a 3K×3K3^K \times 3^K grid. When this grid is divided into nine 3K−1×3K−13^{K-1} \times 3^{K-1} blocks: The central block consists entirely of white cells. The other eight blocks are level-(K−1)(K-1) carpets.

You are given a non-negative integer NN.
Print a level-NN carpet according to the specified format.

输入格式

The input is given from Standard Input in the following format: NN

输出格式

Print 3N3^N lines.
The ii-th line (1≤i≤3N1 \leq i \leq 3^N) should contain a string SiS_i of length 3N3^N consisting of .. and #.
The jj-th character of SiS_i (1≤j≤3N1 \leq j \leq 3^N) should be # if the cell at the ii-th row from the top and jj-th column from the left of a level-NN carpet is black, and .. if it is white.

1
###
#.#
###
2
#########
#.##.##.#
#########
###...###
#.#...#.#
###...###
#########
#.##.##.#
#########

提示

0≤N≤60 \leq N \leq 6 NN is an integer.A level-11 carpet is a 3×33 \times 3 grid as follows: When output according to the specified format, it looks like the sample output.
A level-22 carpet is a 9×99 \times 9 grid.

标签: AtCoder|abc357C

来源

AtCoder|abc357C