define _CRT_SECURE_NO_WARNINGS
include[HTML_REMOVED]
include[HTML_REMOVED]
using namespace std;
char pattern[3000][3000], last[3000][3000], picture[3000][3000];
void func(int size,int N )//
{
if (size == 1)
{
for (int i = 0; i < N; i)
{
for (int j = 0; j < N; j)
{
picture[i][j]=pattern[i][j];
}
}
}
else//根据模型,画图案
{
for (int i = 0; i < N; i)
{
for (int j = 0; j < N; j)
{
if (pattern[i][j] == ‘ ‘)
{
for (int pi = i * size; pi < isize + size; pi)
{
for (int pj = j * size; pj < j*size + size; pj)
{
picture[pi][pj] = ‘ ‘;
}
}
}
else
{
for (int pi = i * size; pi < isize + size; pi)
{
for (int pj = j * size; pj < j*size + size; pj)
{
picture[pi][pj] = last[pi - i * size][pj - j * size];
}
}
}
}
}
}
for (int i = 0; i < size*N; i)
{
for (int j = 0; j < size*N; j)
{
last[i][j] = picture[i][j];
}
}
}
int main()
{
int N, Q;
while (1)
{
scanf(“%d”, &N);
if (N == 0)
{
break;
}
getchar();//读取\n
for (int i = 0; i < N; i)
{
for (int j = 0; j < N; j)
{
pattern[i][j] = ‘ ‘;
}
}
for (int i = 0; i < N; i)
{
fgets(pattern[i], 3000, stdin);//fgets读取指定的n个字符,实际只读取n-1个,余一个给\0
}
scanf(“%d”, &Q);
int size = 1;
for (int i = 0; i < Q; i)
{
func(size, N);
size *= N; //分型做法
}
//输出图像
for (int i = 0; i < size; i)
{
for (int j = 0; j < size; j)
{
printf(“%c”, picture[i][j]);
}
printf(“\n”);
}
}
return 0;
}
算法1
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
blablabla
算法2
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
blablabla