九度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基础进阶-终
使用Stream流的方式,遍历集合 import java.util.*; public class StreamDemo{ public static void main(String[] args ...
- 无法获得VMCI 驱动程序的版本: 句柄无效。
写在前面 最近在电脑上安装了VMware虚拟机,在安装系统的使用,总提示错误“无法获得VMCI 驱动程序的版本: 句柄无效.”.最近刚买的电脑,也不会是系统的问题吧,为了装个虚机,总不能重装系统吧,没 ...
- hibernate oneToMany 缓存
@OneToMany(mappedBy="carFieldType", cascade={CascadeType.ALL}, fetch = FetchType.EAGER)@Ca ...
- bootstrap selectpicker使用问题
文档查阅:http://silviomoreto.github.io/bootstrap-select/options/ 1.实用属性 size:5 表示下拉列表默认展示5行(ie8展示4.5行) ...
- javascript if(条件)------------条件中可以使用的值
1.布尔变量true/false2.数字非0,非NaN/ ( 或NaN) NaN--------Not a Number 3.对象非null/(null或undefined) 4.字符串非空串(&qu ...
- c语言字符数组的初始化问题
1.字符数组的定义与初始化 字符数组的初始化,最容易理解的方式就是逐个字符赋给数组中各元素. char str[10]={ 'I',' ','a','m',' ',‘h’,'a','p','p','y ...
- linux使用crontab实现PHP执行定时任务(转)
前几天写过一篇文章,利用单纯的php实现定时执行任务,但是效率不佳,对于linux来说用crontab实现更加合理. 首先说说cron,它是一个linux下的定时执行工具.根用户以外的用户可以使用 c ...
- javascript的slice(),splice(),split(),substring(),substr()
例子摘抄于http://www.w3school.com.cn/jsref/jsref_obj_array.asp 1.slice(): Array和String对象都有 在Array中 slice ...
- BZOJ 2005 NOI2010 能量採集 数论+容斥原理
题目大意:给定n和m.求Σ(1<=i<=n)Σ(1<=j<=m)GCD(i,j)*2-1 i和j的限制不同,传统的线性筛法失效了.这里我们考虑容斥原理 令f[x]为GCD(i, ...
- struct timeval 和 struct timespec
struct timeval { time_t tv_sec; suseconds_t tv_usec; }; 測试代码例如以下: #include <stdio.h> #include ...