POJ 题目2083 Fractal(分治)

Fractal

Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 7937   Accepted: 3807

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

    B(n - 1)        B(n - 1)
    
            B(n - 1)
    
    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
2
3
4
-1

Sample Output

X
-
X X
 X
X X
-
X X   X X
 X     X
X X   X X
   X X
    X
   X X
X X   X X
 X     X
X X   X X
-
X X   X X         X X   X X
 X     X           X     X
X X   X X         X X   X X
   X X               X X
    X                 X
   X X               X X
X X   X X         X X   X X
 X     X           X     X
X X   X X         X X   X X
         X X   X X
          X     X
         X X   X X
            X X
             X
            X X
         X X   X X
          X     X
         X X   X X
X X   X X         X X   X X
 X     X           X     X
X X   X X         X X   X X
   X X               X X
    X                 X
   X X               X X
X X   X X         X X   X X
 X     X           X     X
X X   X X         X X   X X
-

Source

Shanghai 2004 Preliminary

[Submit]   [Go Back]   [Status]   [Discuss]

Home Page
  Go Back  To
top

ac代码

#include<stdio.h>
#include<string.h>
#include<math.h>
char map[1010][1010];
void dfs(int n,int x,int y)
{
	if(n==1)
	{
		map[x][y]='X';
		return;
	}
	int size=pow(3.0,n-2);
	dfs(n-1,x,y);
	dfs(n-1,x,y+2*size);
	dfs(n-1,x+size,y+size);
	dfs(n-1,x+size*2,y);
	dfs(n-1,x+size*2,y+size*2);
}
int main()
{
	int n;
	while(scanf("%d",&n)!=EOF,n!=-1)
	{
		int size=pow(3.0,n-1),i,j;
		for(i=1;i<=size;i++)
		{
			for(j=1;j<=size;j++)
			{
				map[i][j]=' ';
			}
			map[i][j+1]='\0';
		}
		dfs(n,1,1);
		for(i=1;i<=size;i++)
			printf("%s\n",map[i]+1);
		printf("-\n");
	}
}
时间: 2024-10-07 23:05:45

POJ 题目2083 Fractal(分治)的相关文章

ACM训练方案-POJ题目分类

ACM训练方案-POJ题目分类 博客分类: 算法 ACM online Judge 中国: 浙江大学(ZJU):http://acm.zju.edu.cn/ 北京大学(PKU):http://acm.pku.edu.cn/JudgeOnline/ 杭州电子科技大学(HDU):http://acm.hdu.edu.cn/ 中国科技大学(USTC):http://acm.ustc.edu.cn/ 北京航天航空大学(BUAA)http://acm.buaa.edu.cn/oj/index.php 南京

POJ题目(转)

http://www.cnblogs.com/kuangbin/archive/2011/07/29/2120667.html 初期:一.基本算法:     (1)枚举. (poj1753,poj2965)     (2)贪心(poj1328,poj2109,poj2586)     (3)递归和分治法.     (4)递推.     (5)构造法.(poj3295)     (6)模拟法.(poj1068,poj2632,poj1573,poj2993,poj2996)二.图算法:     (

Poj 题目分类

初期:一.基本算法:     (1)枚举. (poj1753,poj2965)     (2)贪心(poj1328,poj2109,poj2586)     (3)递归和分治法.     (4)递推.     (5)构造法.(poj3295)     (6)模拟法.(poj1068,poj2632,poj1573,poj2993,poj2996)二.图算法:     (1)图的深度优先遍历和广度优先遍历.     (2)最短路径算法(dijkstra,bellman-ford,floyd,hea

POJ 题目1659 Frogs&#39; Neighborhood(度数还原无向图)

Frogs' Neighborhood Time Limit: 5000MS   Memory Limit: 10000K Total Submissions: 8348   Accepted: 3538   Special Judge Description 未名湖附近共有N个大小湖泊L1, L2, ..., Ln(其中包括未名湖),每个湖泊Li里住着一只青蛙Fi(1 ≤ i ≤ N).如果湖泊Li和Lj之间有水路相连,则青蛙Fi和Fj互称为邻居.现在已知每只青蛙的邻居数目x1, x2, ..

POJ 题目2411 Mondriaan&#39;s Dream(状压DP)

Mondriaan's Dream Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 13519   Accepted: 7876 Description Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One night, after producing the drawings in his 'toilet series

POJ题目Java代码(一)

POJ 1001 Exponentiation import java.math.BigDecimal; import java.util.Scanner; public class Poj1001 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while(sc.hasNext()){ BigDecimal bigDecimal = new BigDecimal(sc.next())

【转】POJ题目分类

初级:基本算法:枚举:1753 2965贪心:1328 2109 2586构造:3295模拟:1068 2632 1573 2993 2996图:最短路径:1860 3259 1062 2253 1125 2240最小生成树:1789 2485 1258 3026拓扑排序:1094二分图的最大匹配:3041 3020最大流的增广路算法:1459 3436数据结构:串:1035 3080 1936排序:2388 2299哈希表和二分查找等高效查找法:3349 3274 2151 1840 2002

POJ 题目2528 Mayor&#39;s posters(线段树+离散化)

Mayor's posters Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 49564   Accepted: 14361 Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign have been placing their electoral post

POJ 2083 Fractal

问题描述 度为 1 的箱子分形是简单的: X 度为 2 的箱子分形是这样的: X X X X X 如果用 B(n-1)表示度为 n-1 的箱子分形,那么度为 n 的箱子分形可以递归地定义为如下这样: B(n-1)        B(n-1) B(n-1) B(n-1)        B(n-1) 你的任务是画出一个度为 n 的分形. 输入 输入包含若干组测试数据.数据的每行包含一个不大于 7 的正整数 n,输入的最后一行是一个负数 -1 表示输入的结束. 输出 对于每组测试数据,用 X 记号输出