poj Repeater 3768 (模拟&&dfs) 好题
2015-12-05 22:13
471 查看
Repeater
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.
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
Sample Output
Source
这是看了大神博客才会写的。。。
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 4180 | Accepted: 1113 |
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; }
相关文章推荐
- cmd正则表达式批量重命名
- android html解析
- 容器的同步控制与只读设置JAVA133
- UIVIew之霓虹灯实现
- 利用switch语句解决问题
- python核心编程-filter函数
- 第二个Sprint冲刺团队贡献分
- HDOJ 5591 ZYB's Game(简单博弈)
- Qt 创建上下文菜单
- 为学无他,争千秋勿争一日
- Git基本的工作流程
- 【IO模型探讨】阻塞,非阻塞,同步,异步
- Shiro介绍(二):从简单的认证开始
- JavaScript中的作用域
- 编程基础知识之浮点型
- redis的简介和配置
- CSU 1547 背包
- 【Data Structure】nlogn-SortMethods(Quick/Heap/Shell/Merge)
- UILabel、UIImageView、UIButton的使用
- 基于数据挖掘的客户流失分析案例