九度OJ 1161:Repeater(复制器) (递归)
时间限制: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
思路:
开始以为这个题很难,后来发现起始就是基于模板画图,用递归来做就行。
容易出细节错误。
代码:
#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(复制器) (递归)的更多相关文章
- 九度OJ 1073:杨辉三角形 (递归)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:3780 解决:1631 题目描述: 输入n值,使用递归函数,求杨辉三角形中各个位置上的值. 输入: 一个大于等于2的整型数n 输出: 题目可 ...
- 九度OJ 1092:Fibonacci (递归)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:1923 解决:1378 题目描述: The Fibonacci Numbers{0,1,1,2,3,5,8,13,21,34,55...} ...
- 九度OJ 1338:角斗士 (递归、DP)
时间限制:3 秒 内存限制:32 兆 特殊判题:否 提交:213 解决:66 题目描述: 角斗士是古罗马奴隶社会的一种特殊身份的奴隶,他们的职责是在角斗场上进行殊死搏斗,为了人们提供野蛮的娱乐.他们的 ...
- 【九度OJ】题目1078:二叉树遍历 解题报告
[九度OJ]题目1078:二叉树遍历 解题报告 标签(空格分隔): 九度OJ http://ac.jobdu.com/problem.php?pid=1078 题目描述: 二叉树的前序.中序.后序遍历 ...
- 【九度OJ】题目1474:矩阵幂 解题报告
[九度OJ]题目1474:矩阵幂 解题报告 标签(空格分隔): 九度OJ http://ac.jobdu.com/problem.php?pid=1474 题目描述: 给定一个n*n的矩阵,求该矩阵的 ...
- 【九度OJ】题目1073:杨辉三角形 解题报告
[九度OJ]题目1073:杨辉三角形 解题报告 标签(空格分隔): 九度OJ http://ac.jobdu.com/problem.php?pid=1073 题目描述: 输入n值,使用递归函数,求杨 ...
- 【九度OJ】题目1205:N阶楼梯上楼问题 解题报告
[九度OJ]题目1205:N阶楼梯上楼问题 解题报告 标签(空格分隔): 九度OJ http://ac.jobdu.com/problem.php?pid=1205 题目描述: N阶楼梯上楼问题:一次 ...
- 九度oj 题目1087:约数的个数
题目链接:http://ac.jobdu.com/problem.php?pid=1087 题目描述: 输入n个整数,依次输出每个数的约数的个数 输入: 输入的第一行为N,即数组的个数(N<=1 ...
- 九度OJ 1502 最大值最小化(JAVA)
题目1502:最大值最小化(二分答案) 九度OJ Java import java.util.Scanner; public class Main { public static int max(in ...
随机推荐
- Java NIO.2 Files类的常用方法
Files类是一个工具类,提供了大量的静态方法来操作文件.文件夹. Files类常用方法: long size(Path path) //返回文件大小 boolean isDirectory ...
- Java中Properties配置文件读取
以下实践的是Properties配置文件的基本操作方法.像spring使用xml做依赖注入时,这个配置文件起到非常实用的作用. 一.格式规范 参考wiki百科的格式简介:https://zh.wiki ...
- pandas常用操作
删除某列: concatdfs.drop('Unnamed: 0',axis=1) 打印所有列名: .columns
- java项目热加载工具jrebel
flask有热加载的功能,修为代码后,自动生效. java项目也有类似的功能,不过需要使用收费的插件jrebel 提供一个免费的注册服务器:http://139.199.89.239:1008/884 ...
- H5 性能调优 工具
1.阿里测:http://www.alibench.com 2.奇云测:http://ce.cloud.360.cn 3.百度应用性能检测中心:http://apm.baidu.com 推荐理由:这3 ...
- JavaScript学习与实践一
一.JavaScript数组 创建JavaScript数组有两种方式 方式一: var cars=new Array(); cars[0]="Audi"; cars[1]=&quo ...
- 摄像机Rtsp地址格式大全
各厂家rtsp地址格式如下: 一. 海康.中威摄像机 格式1 主码流:rtsp://admin:12345@192.168.1.64:554/Streaming/Channels/1 子码流:rts ...
- CPU核心电压与VID电压
1.CPU核心电压与VID电压的区别 VID是CPU电压识别信号,CPU的工作电压就是由VID来定义的,CPU核心电压是CPU正常工作所需的电压 原理: (1)通常主板上用硬件VID确定BOOT VI ...
- MySql(六):影响 MySQL Server 性能的相关因素
MySQL 最多的使用场景是WEB 应用,那么我们就以一个WEB 应用系统为例,逐个分析其系统构成,进行经验总结,分析出数据库应用系统中各个环境对性能的影响. 一.商业需求对性能的影响 这里我们就拿一 ...
- win10系统架构调用
操作系统模型 操作系统有两种模式: 用户模式 内核模式 当用户模式调用系统服务时,CPU执行一个特殊的指令以切换到内核模式(Ring0),当系统服务调用完成时,操作系统切换回用户模式(Ring3). ...