zoukankan      html  css  js  c++  java
  • POJ 1941 The Sierpinski Fractal ——模拟

    只需要开一个数组,记录一下这个图形。

    通过一番计算,发现最大的面积大约是2k*2k的

    然后递归下去染三角形。

    需要计算出左上角的坐标。

    然后输出的时候需要记录一下每一行最远延伸的地方,防止行末空格过多。

    然后需要用putchar

    #include <map>
    #include <cmath>
    #include <queue>
    #include <cstdio>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    using namespace std;
    #define F(i,j,k) for (int i=j;i<=k;++i)
    #define D(i,j,k) for (int i=j;i>=k;--i)
    #define ll long long
    #define mp make_pair
    #define maxn 2050
    
    char s[maxn][maxn];
    
    int l[11]={0,4,8,16,32,64,128,256,512,1024,2048},n,h[11]={0,2,4,8,16,32,64,128,256,512,1024};
    int upper[maxn],high=0;
    
    inline void solve(int x,int y,int siz)
    {
    	if (!siz) return;
    	if (siz==1)
    	{
    		s[x][y]=' ';
    		s[x][y+1]='/';
    		s[x][y+2]='\';
    		s[x+1][y]='/';
    		s[x+1][y+3]='\';
    		s[x+1][y+1]='_';
    		s[x+1][y+2]='_';
    		upper[x]=max(upper[x],y+2);
    		upper[x+1]=max(upper[x],y+3);
    		high=max(high,x+1);
    		return ;
    	}
    	F(i,x,x+h[siz-1]-1) F(j,y,l[siz-1]/2+y-1) s[i][j]=' ';
    	solve(x,y+l[siz-1]/2,siz-1);
    	solve(x+h[siz-1],y,siz-1);
    	solve(x+h[siz-1],y+l[siz-1],siz-1);
    }
    
    int main()
    {
    	while(scanf("%d",&n)!=EOF&&n)
    	{
    		F(i,0,h[n]) F(j,0,l[n]) s[i][j]=' ';
    		high=0;memset(upper,0,sizeof upper);
    		solve(0,0,n);
    		F(i,0,high)
    		{
    			F(j,0,upper[i]) putchar(s[i][j]);
    			putchar('
    ');
    		}
    		putchar('
    ');
    	}
    }
    

      

  • 相关阅读:
    CSS3实现小黄人动画
    CSS3实现时间轴效果
    CSS3实现8种Loading效果【二】
    Delphi面向对象的编程思想
    delphi 格式转换
    FindWindow和FindWindowEx函数使用
    delphi TStringList 用法详解
    ExtractFileDir 与 ExtractFilePath 的区别
    C++模板与群体数据
    C++多态性
  • 原文地址:https://www.cnblogs.com/SfailSth/p/6877168.html
Copyright © 2011-2022 走看看