hrbust2291

来源:互联网 发布:pdf.js获取pdf高度 编辑:程序博客网 时间:2024/05/21 22:36

Help C5Time Limit: 1000 MSMemory Limit: 65535 KTotal Submit: 172(40 users)Total Accepted: 52(38 users)Rating: Special Judge: NoDescriptionHello, I’m Sea5, and you can call me C5 instead. I want a program which can sign my name automatically. And my brothers, C0, C1, C2, C3, C4, C6, C7, C8, each of them wants one as well. Can you help us?Input

First line is the number of test cases T(T<=8).

T lines follow, each line includes an integer N(N<=7), and you should help C(N) to sign his name.

Output

C0’s signature is ‘C’.

When you draw C(N)’s name, you should print the name using C(N-1)’s name as its element, and using the following format to draw it.

*XX

X**

*XX

(X is the element, * is blank space)

And please don’t print extra spaces at the end of line.

For example, C1’s name should be

*CC                    *CC

C                      C**

*CC     But not    *CC

(I use * to show you where are spaces.)

Sample Input3
0
1
2Sample Output

C
 CC
C
 CC
    CC CC
   C  C
    CC CC
 CC
C
 CC
    CC CC
   C  C
    CC CC

代码:

#include<iostream>
#include<string.h>
#include<map>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
using namespace std;
char a[3000][3000];
void dfs(int n,int x,int y)
{
    if(n==1)
    {
        a[x][y]='C';
        return ;
    }
    else
    {
        int size=pow(3,n-2);
        dfs(n-1,x,y+size);
        dfs(n-1,x,y+size+size);
        dfs(n-1,x+size,y);
        dfs(n-1,x+size+size,y+size);
        dfs(n-1,x+size+size,y+size+size);
    }
}
int main()
{
    int t,q;
    cin>>t;
    while(t--)
    {
        cin>>q;
        int size=pow(3,q);
        for(int i=1;i<=size;i++)
        {
            for(int j=1;j<=size;j++)
            {
                a[i][j]=' ';
            }
        }
        dfs(q+1,1,1);
        for(int i=1;i<=size;i++)
        {
            for(int j=size;j>=1;j--)
            {
                if(a[i][j]=='C')
                {
                    a[i][j+1]='\0';
                    break;
                }
            }
        }
        for(int i=1;i<=size;i++)
        {
            printf("%s\n",a[i]+1);
        }
    }
}

0 0
原创粉丝点击