Description

A fractal is an object or quantity that displays self-similarity, in a somewhat technical sense, on all scales. The object need not exhibit exactly the same structure at all scales, but the same "type" of structures must appear on all scales. 
A box fractal is defined as below :

  • A box fractal of degree 1 is simply 
    X
  • A box fractal of degree 2 is 
    X X 

    X X
  • If using B(n - 1) to represent the box fractal of degree n - 1, then a box fractal of degree n is defined recursively as following 
    1. B(n - 1) B(n - 1)

    2. B(n - 1)

    3. B(n - 1) B(n - 1)

Your task is to draw a box fractal of degree n.

Input

The input consists of several test cases. Each line of the input contains a positive integer n which is no greater than 7. The last line of input is a negative integer −1 indicating the end of input.

Output

For each test case, output the box fractal using the 'X' notation. Please notice that 'X' is an uppercase letter. Print a line with only a single dash after each test case.

Sample Input

  1. 1
  2. 2
  3. 3
  4. 4
  5. -1

Sample Output

  1. X
  2. -
  3. X X
  4. X
  5. X X
  6. -
  7. X X X X
  8. X X
  9. X X X X
  10. X X
  11. X
  12. X X
  13. X X X X
  14. X X
  15. X X X X
  16. -
  17. X X X X X X X X
  18. X X X X
  19. X X X X X X X X
  20. X X X X
  21. X X
  22. X X X X
  23. X X X X X X X X
  24. X X X X
  25. X X X X X X X X
  26. X X X X
  27. X X
  28. X X X X
  29. X X
  30. X
  31. X X
  32. X X X X
  33. X X
  34. X X X X
  35. X X X X X X X X
  36. X X X X
  37. X X X X X X X X
  38. X X X X
  39. X X
  40. X X X X
  41. X X X X X X X X
  42. X X X X
  43. X X X X X X X X
  44. -
    解析
    一道比较简单的分形图,n<=7,则边长最大为739,开一个800*800的数组记录当前是“X”还是“ ”,当他处于第n级时,如果需要向n-1级递归,就有五个方向:
    左上角,右上角,中间,左下角,右下角。
  1. #include<cstring>
  2. #include<cstdio>
  3. #include<cmath>
  4. using namespace std;
  5. int n;
  6. bool maps[][];
  7. inline void dfs(int m,int bian,int xx,int yy)
  8. {
  9. if(m==){
  10. maps[xx][yy]=;
  11. return;
  12. }
  13. dfs(m-,bian/,xx-bian/,yy-bian/);
  14. dfs(m-,bian/,xx-bian/,yy+bian/);
  15. dfs(m-,bian/,xx+bian/,yy-bian/);
  16. dfs(m-,bian/,xx+bian/,yy+bian/);
  17. dfs(m-,bian/,xx,yy);
  18. }
  19. int main()
  20. {
  21. while()
  22. {
  23. memset(maps,,sizeof maps);
  24. scanf("%d",&n);
  25. if(n==-)break;
  26. int bian=;
  27. for(int i=;i<=n-;i++) bian*=;
  28. dfs(n,bian,(bian+)/,(bian+)/);//分别传入第n级,边长(长 和 高相等),中心位置的横纵坐标
  29. for(register int i=;i<=bian;i++)
  30. {
  31. for(register int j=;j<=bian;j++)
  32. {
  33. if(maps[i][j])printf("X");
  34. else printf(" ");
  35. }
  36. printf("\n");
  37. }
  38. printf("-\n");
  39. }
  40. }
  1.  
  1.  

[POJ2083] Fracal的更多相关文章

  1. poj2083 Fractal

    我一开始的想法是间断性的输出空格和solve(k-1) 但是发现问题很大. 雨菲:可以用一个数组保存啊 我:那不爆了? 雨菲:不会爆. 我一算:729 × 729,还真没爆. 然后就直接WA了.... ...

  2. poj2083 分形(图形的递归)

    题目传送门 代码有注释. #include<iostream> #include<algorithm> #include<cstdlib> #include< ...

  3. POJ-2083 Fractal-X星阵图

    Description A fractal is an object or quantity that displays self-similarity, in a somewhat technica ...

  4. $Poj2083/AcWing118\ Fractal$ 模拟

    $AcWing$ $Sol$ 一年前做过差不多的南蛮图腾,当时做出来还是很有成就感的$OvO$ $N<=7$,就是模拟模拟,预处理一下,$over$ $Code$ #include<bit ...

  5. Servlet3.0学习总结(二)——使用注解标注过滤器(Filter)

    Servlet3.0提供@WebFilter注解将一个实现了javax.servlet.Filter接口的类定义为过滤器,这样我们在web应用中使用过滤器时,也不再需要在web.xml文件中配置过滤器 ...

  6. A过的题目

    1.TreeMap和TreeSet类:A - Language of FatMouse ZOJ1109B - For Fans of Statistics URAL 1613 C - Hardwood ...

  7. MySQL 高性能存储引擎:TokuDB初探

    在安装MariaDB的时候了解到代替InnoDB的TokuDB,看简介非常的棒,这里对ToduDB做一个初步的整理,使用后再做更多的分享. 什么是TokuDB? 在MySQL最流行的支持全事务的引擎为 ...

  8. MySQL-TokuDB:MySQL 高性能存储引擎:TokuDB

    ylbtech-MySQL-TokuDB:MySQL 高性能存储引擎:TokuDB 1.返回顶部 1. 在安装MariaDB的时候了解到代替InnoDB的TokuDB,看简介非常的棒,这里对ToduD ...

随机推荐

  1. DDD分层架构的三种模式

    引言 在讨论DDD分层架构的模式之前,我们先一起回顾一下DDD和分层架构的相关知识. DDD DDD(Domain Driven Design,领域驱动设计)作为一种软件开发方法,它可以帮助我们设计高 ...

  2. 前端与算法 leetcode 28.实现 strStr()

    # 前端与算法 leetcode 28.实现 strStr() 题目描述 28.移除元素 概要 这道题的意义是实现一个api,不是调api,尽管很多时候api的速度比我们写的快(今天这个我们可以做到和 ...

  3. Spring 通过@Import实现Bean的注册

    今天看到一个神奇的用法, Spring可以通过@Import导入实现了ImportBeanDefinitionRegistrar接口的类来注册那个类. ImportBeanDefinitionRegi ...

  4. Codeforces Round #603 (Div. 2) (题解)

    A. Sweet Problem (找规律) 题目链接 大致思路: 有一点瞎猜的,首先排一个序, \(a_1>a_2>a_3\) ,发现如果 \(a_1>=a_2+a_3\) ,那么 ...

  5. C++中const限定符

    const基础 C++中的const,用于定义一个常量,这个常量的值不能被修改.因为const对象一旦创建就不能修改,所以const对象必须初始化.const常量特征仅仅在执行改变其本身的操作时才会发 ...

  6. 安装nginx1.16.1版本

    安装nginx1.16.1版本 一.添加源 到 cd /etc/yum.repos.d/ 目录下 新建nginx.repo 文件 vim nginx.repo 输入以下信息 [nginx-stable ...

  7. 【LEETCODE】64、链表分类,medium&hard级别,题目:2,138,142,23

    package y2019.Algorithm.LinkedList.medium; import y2019.Algorithm.LinkedList.ListNode; /** * @Projec ...

  8. 转!!DBCP2 配置详解说明

    转自:https://www.cnblogs.com/diyunpeng/p/6980098.html 由于commons-dbcp所用的连接池出现版本升级,因此commons-dbcp2中的数据库池 ...

  9. Maven的仓库和settings.xml配置文件

    (尊重劳动成果,转载请注明出处:https://blog.csdn.net/qq_25827845/article/details/83549846冷血之心的博客) 快速导航: Maven基础概念和安 ...

  10. ajax标准写法

    ajax 标准写法 $.ajax({ url:"http://www.microsoft.com", //请求的url地址 dataType:"json", / ...