九度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数据结构和算法10(堆)
这篇我们说说堆这种数据结构,其实到这里就暂时把java的数据结构告一段落,感觉说的也差不多了,各种常见的数据结构都说到了,其实还有一种数据结构是“图”,然而暂时对图没啥兴趣,等有兴趣的再说:还有排序算 ...
- 获取元素位置信息和所占空间大小(via:js&jquery)
工作中有一个很常见的需求,hover或者click某元素后,在该元素旁边出现弹框,主要就是获取该元素的位置坐标以及元素所占区块的大小.最近工作中就遇到了,发现js和jquery的实现方法有很大的区别, ...
- 聊聊、Zookeeper 客户端 Curator
[Curator] 和 ZkClient 一样,Curator 也是开源客户端,Curator 是 Netflix 公司开源的一套框架. <dependency> <groupI ...
- hdu1862
//开始把student stu[100000]放置在main()中导致栈溢出,所以必须放在全局位置, //可以调用数组的排序函数sort,包含头文件#include<algorithm> ...
- LCD设备驱动程序
LCD是Liquid Crystal Display的简称,也就是经常所说的液晶显示器 LCD能够支持彩色图像的显示和视频的播放,是一种非常重要的输出设备 Framebuffer 是Linux系统 ...
- 2016.11.4 Injection of autowired dependencies failed
运行项目时,提示错误: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ' ...
- Win10蓝屏代码
UNEXPECTED_STORE_EXCEPTION “意外存储异常”是Windows 10上的“停止错误”,表示存储组件发生意外异常. 原因 固态硬盘驱动与当前固态硬盘驱动程序不兼容或是当前固态硬盘 ...
- Kali Linux 1.0 新手折腾笔记(2013.3.21更新)
rootoorotor昨天折腾了 Kali Linux 1.0,把大概的配置过程记录下来,希望对想接触或使用Kali Linux的同学有所帮助. 请注意: 1.本文为面向新手的教程,没技术含量,没事瞎 ...
- C 作用域规则
C 作用域规则 任何一种编程中,作用域是程序中定义的变量所存在的区域,超过该区域变量就不能被访问.C 语言中有三个地方可以声明变量: 在函数或块内部的局部变量 在所有函数外部的全局变量 在形式参数的函 ...
- UISegmentedControl的具体使用
当用户输入不不过布尔值时.可使用分段控件(UISegmentedControl).分段控件提供一栏button(有时称为button栏),但只能激活当中一个button. 分段控件会导致用户在屏幕上看 ...