时间限制:1 秒

内存限制:32 兆

特殊判题:否

提交:1449

解决:508

题目描述:

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 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.

输出:

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

样例输入:
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
来源:
2011年北京大学计算机研究生机试真题

思路:

开始以为这个题很难,后来发现起始就是基于模板画图,用递归来做就行。

容易出细节错误。

代码:

#include <stdio.h>
#include <string.h>
#include <math.h> #define N 3000
#define M 5 char p[N][N+1];
char tem[M][M+1];
int m; void cp(int x, int y)
{
int i, j;
for (i=0; i<m; i++)
{
for (j=0; j<m; j++)
{
p[i+x][j+y] = tem[i][j];
}
}
} void set(int n, int x, int y)
{
if (n == 1)
{
cp(x, y);
return;
}
int i, j;
int size = pow(m, n-1);
for (i=0; i<m; i++)
{
for (j=0; j<m; j++)
{
if (tem[i][j] != ' ')
set(n-1, x+i*size, y+j*size);
}
}
} void print(int n)
{
int size = pow(m, n);
for (int i=0; i<size; i++)
{
for (int j=0; j<size; j++)
{
printf("%c", p[i][j]);
}
printf("\n");
}
} int main(void)
{
int n, i, j;
while (scanf("%d", &m) != EOF && m)
{
getchar();
for (i=0; i<N; i++)
{
for (j=0; j<N; j++)
p[i][j] = ' ';
p[i][N] = '\0';
}
for (i=0; i<m; i++)
{
gets(tem[i]);
}
scanf("%d", &n);
getchar();
set(n, 0, 0);
print(n);
} return 0;
}
/**************************************************************
Problem: 1161
User: liangrx06
Language: C
Result: Accepted
Time:260 ms
Memory:9796 kb
****************************************************************/

九度OJ 1161:Repeater(复制器) (递归)的更多相关文章

  1. 九度OJ 1073:杨辉三角形 (递归)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:3780 解决:1631 题目描述: 输入n值,使用递归函数,求杨辉三角形中各个位置上的值. 输入: 一个大于等于2的整型数n 输出: 题目可 ...

  2. 九度OJ 1092:Fibonacci (递归)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:1923 解决:1378 题目描述: The Fibonacci Numbers{0,1,1,2,3,5,8,13,21,34,55...} ...

  3. 九度OJ 1338:角斗士 (递归、DP)

    时间限制:3 秒 内存限制:32 兆 特殊判题:否 提交:213 解决:66 题目描述: 角斗士是古罗马奴隶社会的一种特殊身份的奴隶,他们的职责是在角斗场上进行殊死搏斗,为了人们提供野蛮的娱乐.他们的 ...

  4. 【九度OJ】题目1078:二叉树遍历 解题报告

    [九度OJ]题目1078:二叉树遍历 解题报告 标签(空格分隔): 九度OJ http://ac.jobdu.com/problem.php?pid=1078 题目描述: 二叉树的前序.中序.后序遍历 ...

  5. 【九度OJ】题目1474:矩阵幂 解题报告

    [九度OJ]题目1474:矩阵幂 解题报告 标签(空格分隔): 九度OJ http://ac.jobdu.com/problem.php?pid=1474 题目描述: 给定一个n*n的矩阵,求该矩阵的 ...

  6. 【九度OJ】题目1073:杨辉三角形 解题报告

    [九度OJ]题目1073:杨辉三角形 解题报告 标签(空格分隔): 九度OJ http://ac.jobdu.com/problem.php?pid=1073 题目描述: 输入n值,使用递归函数,求杨 ...

  7. 【九度OJ】题目1205:N阶楼梯上楼问题 解题报告

    [九度OJ]题目1205:N阶楼梯上楼问题 解题报告 标签(空格分隔): 九度OJ http://ac.jobdu.com/problem.php?pid=1205 题目描述: N阶楼梯上楼问题:一次 ...

  8. 九度oj 题目1087:约数的个数

    题目链接:http://ac.jobdu.com/problem.php?pid=1087 题目描述: 输入n个整数,依次输出每个数的约数的个数 输入: 输入的第一行为N,即数组的个数(N<=1 ...

  9. 九度OJ 1502 最大值最小化(JAVA)

    题目1502:最大值最小化(二分答案) 九度OJ Java import java.util.Scanner; public class Main { public static int max(in ...

随机推荐

  1. Longest Increasing Subsequence - LeetCode

    Given an unsorted array of integers, find the length of longest increasing subsequence. For example, ...

  2. OnTouchListener

    1.布局 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android ...

  3. 【spring boot logback】日志使用自定义的logback-spring.xml文件后,application.properties中关于日志的相关配置还会起作用么

    本篇 将针对[日志使用自定义的logback-spring.xml文件后,application.properties中关于日志的相关配置还会起作用么]这一个主题进行探索. 这个测试项目是根据[spr ...

  4. 如何让你的网页加载时间降低到 1s 内

    当初分析了定宽高值和定宽高比这两种常见的图片延迟加载场景,也介绍了他们的应对方案,还做了一点技术选型的工作. 经过一段时间的项目实践,在先前方案的基础上又做了很多深入的优化工作.最终将好奇心日报的网页 ...

  5. Android Studio和MAT结合使用来分析内存问题

    Android开发中时常会遇到内存泄漏的问题,而Android系统对单个App又有一定的内存限制,此值可以通过一下方式获取: ActivityManager am = (ActivityManager ...

  6. Linux内核的引导

    1,当系统上电或复位时,CPU会将PC指针赋值为一个特定的地址0xFFFF0并执行该地址处的指令.在PC机中,该地址位于BIOS中,它保存在主板上的ROM或Flash中 2,BIOS运行时按照CMOS ...

  7. fastjson的常用用法以及自定义排序

    fastJson的四种常用方法 JSON 转 POJO public static <T> T getObject(String pojo, Class<T> tclass) ...

  8. 2017.3.14 activiti实战--第二十章--REST服务

    学习资料:<Activiti实战> 第二十章 REST服务 20.1 通信协议概述 略. 20.2 REST API概述 资源分类 资源基础URI 说明 Deployments manag ...

  9. 微信小程序 - 下载图片并且显示进度

    lastUpDate: 2018-8-12 请把请求地址加入到downLoadFile 提示:首先得要在公众号设置对应的downLoadFile地址. downImg : 下载图片 wxml js d ...

  10. Android开发第一讲之目录结构和程序的执行流程

    1.如何在eclipse当中,修改字体 下面的这种办法,可以更改xml的字体 窗口--首选项--常规--外观--颜色和字体--基本--文本字体--编辑Window --> Preferences ...