KY58 Repeater
作者:互联网
描述
Harmony is indispensible in our daily life and no one can live without it----may be Facer is the only exception. One day it is rumored that repeat painting will create harmony and then hundreds of people started their endless drawing. Their paintings were based on a small template and a simple method of duplicating. Though Facer can easily imagine the style of the whole picture, but he cannot find the essential harmony. Now you need to help Facer by showing the picture on computer. You will be given a template containing only one kind of character and spaces, and the template shows how the endless picture is created----use the characters as basic elements and put them in the right position to form a bigger template, and then repeat and repeat doing that. Here is an example. # # # <-template # # So the Level 1 picture will be # # # # # Level 2 picture will be # # # # # # # # # # # # # # # # # # # # # # # # #
输入描述:
The input contains multiple test cases. The first line of each case is an integer N, representing the size of the template is NN (N could only be 3, 4 or 5). Next N lines describe the template. The following line contains an integer Q, which is the Scale Level of the picture. Input is ended with a case of N=0. It is guaranteed that the size of one picture will not exceed 30003000.
输出描述:
For each test case, just print the Level Q picture by using the given template.
示例1
输入:
3
# #
#
# #
1
3
# #
#
# #
3
4
OO
O O
O O
OO
2
0
输出:
# #
#
# #
# # # # # # # #
# # # #
# # # # # # # #
# # # #
# #
# # # #
# # # # # # # #
# # # #
# # # # # # # #
# # # #
# #
# # # #
# #
#
# #
# # # #
# #
# # # #
# # # # # # # #
# # # #
# # # # # # # #
# # # #
# #
# # # #
# # # # # # # #
# # # #
# # # # # # # #
OO OO
O OO O
O OO O
OO OO
OO OO
O O O O
O O O O
OO OO
OO OO
O O O O
O O O O
OO OO
OO OO
O OO O
O OO O
OO OO
题目大意:
给你一个仅包含一种字符和空格的模板,模板显示如何创建无尽的图片,将字符用作基本元素并将它们放在正确的位置以形成更大模板,然后不断进行该操作。
知识点: 暴力求解 模拟 递归
AC代码:
#include <bits/stdc++.h>
using namespace std;
int N;
char temp[10][10]; // 存放template模板
char picture[3005][3005]; // 存放最终picture
void draw(int Q, int a, int b) // 递归画每一个level
{
if(Q == 1) // level1
{
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
{
picture[a + i][b + j] = temp[i][j];
}
}
}
else
{
int unit = pow(N, Q - 1); // 以上一level为一个单元
for (int i = 0; i < N; i++) // 遍历模板template
{
for (int j = 0; j < N; j++)
{
if(temp[i][j] != ' ')
{
draw(Q - 1, a + i * unit, b + j * unit);
}
}
}
}
}
int main()
{
while(cin >> N)
{
if(N == 0)
{
break;
}
getchar();
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
{
temp[i][j] = getchar();
}
getchar();
}
int Q;
cin >> Q;
for (int i = 0; i < 3005; i++)
{
for (int j = 0; j < 3005; j++)
{
picture[i][j] = ' ';
}
}
int length = pow(N, Q); // column
draw(Q, 0, 0);
for(int i = 0; i < length; i++)
{
for(int j = 0; j < length; j++)
{
cout << picture[i][j];
}
cout << endl;
}
}
}
标签:OO,picture,Repeater,int,KY58,++,template,模板 来源: https://blog.csdn.net/qq_46620129/article/details/121478282