Repeater

POJ - 3768

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

# #   # #

 #     #

# #   # #

   # #   

    #    

   # #   

# #   # #

 #     # 

# #   # #

Input

The input contains multiple test cases.

The first line of each case is an integer N, representing the size of the template is NN (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.

Output

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

Sample Input

3
# #
#
# #
1
3
# #
#
# #
3
4
OO
O O
O O
OO
2
0

Sample Output


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

思路:

分形的经典问题,

将大图形转为很多个小图形处理,小图形也继续分为更小的图形处理。

用dfs递归操作即可,要维护好当前图形的左上角的坐标和当前步骤的图形尺寸(边长),以及当前是第几层,到第一层的时候直接赋值为单元元素。

个人觉得自己写法属于比较简单的。

细节见代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define sz(a) int(a.size())
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define chu(x) cout<<"["<<#x<<" "<<(x)<<"]"<<endl
#define du3(a,b,c) scanf("%d %d %d",&(a),&(b),&(c))
#define du2(a,b) scanf("%d %d",&(a),&(b))
#define du1(a) scanf("%d",&(a));
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
ll powmod(ll a, ll b, ll MOD) {a %= MOD; if (a == 0ll) {return 0ll;} ll ans = 1; while (b) {if (b & 1) {ans = ans * a % MOD;} a = a * a % MOD; b >>= 1;} return ans;}
void Pv(const vector<int> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf("%d", V[i] ); if (i != Len - 1) {printf(" ");} else {printf("\n");}}}
void Pvl(const vector<ll> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf("%lld", V[i] ); if (i != Len - 1) {printf(" ");} else {printf("\n");}}} inline void getInt(int* p);
const int maxn = 3000 + 10;
const int inf = 0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/ bool s[maxn][maxn];
char a[maxn][maxn];
int x;
void dfs(int lx, int ly, int rx, int ry, int len, int st)
{
// cout << lx << " " << ly << " " << rx << " " << ry << " " << len << " " << st << endl;
if (len == 1)
{
s[lx][ly] = 1;
return ;
}
int to = len / x;
repd(i, 1, x)
{
rep(j, 0, x)
{
if (a[i][j] != ' ')
{
dfs(lx + (i - 1)*to, ly + (j)*to, lx + (i - 1)*to + to - 1, ly + (j)*to + to - 1, to, st - 1);
}
}
} }
char base;
int main()
{
//freopen("D:\\code\\text\\input.txt","r",stdin);
//freopen("D:\\code\\text\\output.txt","w",stdout);
while (~scanf("%d", &x))
{
if (!x)
{
break;
}
// cin >> base;
getchar();
repd(i, 1, x)
{
gets(a[i]);
// getline(cin, a[i]);
}
repd(i, 1, x)
{
rep(j, 0, x)
{
if (a[i][j] != ' ')
{
base = a[i][j];
}
// cout<<a[i][j];
}
// cout<<endl;
}
// chu(base);
int step;
// cin >> step;
scanf("%d", &step);
int len = (int)(pow(x, step) + 0.5);
dfs(1, 1, len, len, len, step);
repd(i, 1, len)
{
repd(j, 1, len)
{
if (s[i][j])
{
putchar(base);
// cout << base;
} else
{
putchar(' ');
// cout << ' ';
}
s[i][j] = 0;
}
putchar('\n');
// cout << endl;
}
} return 0;
} inline void getInt(int* p) {
char ch;
do {
ch = getchar();
} while (ch == ' ' || ch == '\n');
if (ch == '-') {
*p = -(getchar() - '0');
while ((ch = getchar()) >= '0' && ch <= '9') {
*p = *p * 10 - ch + '0';
}
}
else {
*p = ch - '0';
while ((ch = getchar()) >= '0' && ch <= '9') {
*p = *p * 10 + ch - '0';
}
}
}

Repeater POJ - 3768 (分形)的更多相关文章

  1. POJ 2083 Fractal 分形

    去年校赛团队赛就有一道分形让所有大一新生欲生欲死…… 当时就想学了 结果一直拖到…… 今天上午…… 马上要省选了 才会一点基础分形…… 还是自己不够努力啊…… 分形主要是要找到递归点…… 还有深度…… ...

  2. POJ 2083 Fractal 分形题目

    这两天自学了一线算法导论里分治策略的内容,秉着只有真正投入投入编程,才能更好的理解一种算法的思想的想法,兴致勃勃地找一些入门的题来学习. 搜了一下最后把目光锁定在了Poj fractal这一个题上.以 ...

  3. 迭代加深搜索 POJ 1129 Channel Allocation

    POJ 1129 Channel Allocation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 14191   Acc ...

  4. poj 题目分类(1)

    poj 题目分类 按照ac的代码长度分类(主要参考最短代码和自己写的代码) 短代码:0.01K--0.50K:中短代码:0.51K--1.00K:中等代码量:1.01K--2.00K:长代码:2.01 ...

  5. POJ题目分类(按初级\中级\高级等分类,有助于大家根据个人情况学习)

    本文来自:http://www.cppblog.com/snowshine09/archive/2011/08/02/152272.spx 多版本的POJ分类 流传最广的一种分类: 初期: 一.基本算 ...

  6. 【转载】图论 500题——主要为hdu/poj/zoj

    转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...

  7. POJ题目细究

    acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP:  1011   NTA                 简单题  1013   Great Equipment     简单题  102 ...

  8. 转载:poj题目分类(侵删)

    转载:from: POJ:http://blog.csdn.net/qq_28236309/article/details/47818407 按照ac的代码长度分类(主要参考最短代码和自己写的代码)  ...

  9. SurfaceView 绘制分形图

    之前一直做的是应用类,这次抽时间,参考网上资料实践了下SurfaceView.目标是在页面上画一个科赫曲线的分形图. 代码如下: package com.example.fredric.demo02; ...

随机推荐

  1. git clone、 remote、fetch、pull、push、remote

    git clone命令笔记 作用:远程克隆版本库 1. 克隆版本库 git clone <版本库的网址> git clone zoran@192.168.2.167:/data/gitda ...

  2. Telegram Groups vs Telegram Channels

    Telegram Groups vs Telegram Channels By Iaroslav Kudritskiy  Unlike other messaging apps, using Tele ...

  3. MySQL索引解析(联合索引/最左前缀/覆盖索引/索引下推)

    本节内容: 1)索引基础 2)索引类型(Hash索引.有序数组.B+树) 3)索引的几个常见问题 1)联合索引 2)最左前缀原则 3)覆盖索引 4)索引下推 1. 索引基础 索引对查询的速度有着至关重 ...

  4. 冲刺Noip2017模拟赛4 解题报告——五十岚芒果酱

    题1 韬韬抢苹果(apple) [问题描述] 又到了收获的季节,树上结了许多韬韬,错了,是许多苹果,有很多个小韬韬都来摘苹 果.每个韬韬都想要最大的苹果,所以发生了争执,为了解决他们的矛盾,出题人定了 ...

  5. [OpenCV] sift demo

    运行环境:vs2012+opencv320 sift 需要的头文件为 <opencv2/xfeatures2d.hpp> #include <opencv2/opencv.hpp&g ...

  6. 小菜鸟之SSM框架

    # SSM框架 # **什么是框架** 就是模板,将一些基础性的程序和代码由框架模板提供,然后程序员补充和业务需求相关的代码. # **ssm框架组成** s: springMvc 子框架 代替ser ...

  7. python — 装饰器、迭代器

    目录 1 装饰器 2 迭代器 3 可迭代对象 1 装饰器 1.1目的.应用场景: 目的: 在不改变原函数内部代码的基础上,在函数执行前后自定义功能. 应用场景: 想要为函数扩展功能时,可以选择用装饰器 ...

  8. 使用haystack实现django全文检索搜索引擎功能

    前言 django是python语言的一个web框架,功能强大.配合一些插件可为web网站很方便地添加搜索功能. 搜索引擎使用whoosh,是一个纯python实现的全文搜索引擎,小巧简单. 中文搜索 ...

  9. Linux 创建用户 用户组 用户权限

    首先 你要有个root账号 然后才能做下面几条操作: useradd username 创建用户usernamepasswd user_pwd     给已创建的用户username设置密码 关于us ...

  10. 关于vue-router当中addRoutes的使用

    项目是越写越多,遇到的各种需求当然也逐渐增多. 在一个项目中,实现用户权限,似乎也成了必然. 一直以来,我也知道可以通过vue-router官方提供的一个api-->addRoutes可以实现路 ...