您的位置:首页 > 其它

poj Repeater 3768 (模拟&&dfs) 好题

2015-12-05 22:13 471 查看
Repeater

Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 4180 Accepted: 1113
Description

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



# # # #

# #

# # # #

# # # # #

# # # #

# #

# # # #




Input

The input contains multiple test cases.

The first line of each case is an integer N, representing the size of the template is
N*N (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 3000*3000.

Output

For each test case, just print the Level Q picture by using the given template.

Sample Input
3
# #
#
# #
1
3
# #
#
# #
3
4
OO
O  O
O  O
OO
2
0

Sample Output
# #
#
# #
# #   # #         # #   # #
#     #           #     #
# #   # #         # #   # #
# #               # #
#                 #
# #               # #
# #   # #         # #   # #
#     #           #     #
# #   # #         # #   # #
# #   # #
#     #
# #   # #
# #
#
# #
# #   # #
#     #
# #   # #
# #   # #         # #   # #
#     #           #     #
# #   # #         # #   # #
# #               # #
#                 #
# #               # #
# #   # #         # #   # #
#     #           #     #
# #   # #         # #   # #
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

Source
这是看了大神博客才会写的。。。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string.h>
using namespace std;
char map[3003][3003];
char str[6][6];
int n;
void dfs(int m,int x,int y)
{
int i,j,size;
if(m==1)
{
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
map[x+i][y+j]=str[i][j];
}
return ;
}

size=(int)pow(n*1.0,m-1);

for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(str[i][j]!=' ')
dfs(m-1,x+i*size,y+j*size);
}
}
}
int main(void)
{
int i,j,m,size;
while(scanf("%d",&n),n)
{
getchar();
for(i=0;i<n;i++)
gets(str[i]);
scanf("%d",&m);
size=(int)pow(n*1.0,m);
for(i=0;i<size;i++)
{
for(j=0;j<size;j++)
map[i][j]=' ';
map[i][size]='\0';    //设置每行字符串的结束符)
}
dfs(m,0,0);    //从(0,0)位置处
for(i=0;i<size;i++)
puts(map[i]);    //每次输出一行
}
return 0;
}


 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: