九度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 ...
随机推荐
- OnTouchListener
1.布局 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android ...
- Eclipse的调试功能(转)(让Eclipse也能有VS的即时窗口那样的即时代码调试功能)
前言:可以很明确的说明,eclipse也有像vs那样的即时窗口来运行即时代码的功能. 调试的界面如下: 如果要像vs那样的即时调试功能,需要做一些设置,就是Expressions功能. 开通步骤:Wi ...
- jeffy-vim-v2.8.tgz
vim 配置 jeffy-vim-v2.8.tgz
- java程序容错
程序最怕出错的方式就是直接闪退 编程应该以这种方式进行,保证结构不出错,数据可容错的方式 比如 fungetsonmfrominternet(){变量 a a=从网络返回数据 return a } 在 ...
- autolayout先进的自动布局工具箱
原文链接:http://www.objc.io/issue-3/advanced-auto-layout-toolbox.html 在我的上一个项目中,因为是面向公司内部使用的客户端,所以我直接抛弃了 ...
- flask的安全注意事项,如何防范XSS、CSRF、JSON安全
参考官方文档:http://docs.jinkan.org/docs/flask/security.html 1.xss Flask 配置 Jinja2 自动转义所有值,除非显式地指明不转义.这就排除 ...
- 【GLSL教程】(七)逐像素的光照 【转】
http://blog.csdn.net/racehorse/article/details/6662540 逐像素的方向光(Directional Light per Pixel) 这一节将把前面的 ...
- redis参数配置
redis.conf配置文件 配置项 值 说明 slave-read-only yes slave是否只读 slave-serve-stale-data yes 当slave与master断开连接,s ...
- OCP学习基本知识点总结
下面是我总结的OCP教程的知识点.以备參考之用. 1, What's Oracle Server? · It's a database management system that ...
- apue学习笔记(第六章 系统数据文件和信息)
UNIX系统的正常运作需要使用大量与系统有关的数据文件,例如,口令文件/etc/passwd和组文件/etc/group就是经常被多个程序频繁使用的两个文件. 口令文件 UNIX系统口令文件包含如下字 ...