冰淇淋(图形递归

来源:互联网 发布:类似比邻的软件 编辑:程序博客网 时间:2024/04/28 01:01

传送门

垃圾佬的冰淇淋

TimeLimit:1000MS  MemoryLimit:128MB
64-bit integer IO format:%lld
已解决 | 点击收藏
Problem Description

垃圾佬在草稿纸上画了一颗爱心,如下


/\/\\  / \/


垃圾佬发现,3颗爱心可以拼接成一个冰淇淋(吃货),如下


/\/\/\/\\  /\  / \/\/\/  \  /   \/




现在呢,垃圾佬想画出第N个冰淇淋(上面的分别为第1个,第2个冰淇淋)。可是他还有别的事情要忙。
SO,剩下的冰淇淋就要你来画了。

当然,报酬是有的。。

每画一个,垃圾佬会给你1000000000000000000000000000 mod 10美元的报酬



Input

一个整数N表示第几个冰淇淋

1<=N<=10

Output

输出是你画好的冰淇淋。每行末尾没有多余的空格


SampleInput
3
SampleOutput
/\/\/\/\/\/\/\/\\  /\  /\  /\  / \/\/\/  \/\/\/  \  /    \  /   \/\/\/\/\/    \  /\  /     \/\/\/      \  /       \/

若要绘制一个n阶的冰淇淋,则需要绘制3个n-1阶的冰淇淋,递归下去即可。注意行末没有空格


//china no.1#pragma comment(linker, "/STACK:1024000000,1024000000")#include <vector>#include <iostream>#include <string>#include <map>#include <stack>#include <cstring>#include <queue>#include <list>#include <stdio.h>#include <set>#include <algorithm>#include <cstdlib>#include <cmath>#include <iomanip>#include <cctype>#include <sstream>#include <functional>#include <stdlib.h>#include <time.h>#include <bitset>using namespace std;#define pi acos(-1)#define PI acos(-1)#define endl '\n'#define srand() srand(time(0));#define me(x,y) memset(x,y,sizeof(x));#define foreach(it,a) for(__typeof((a).begin()) it=(a).begin();it!=(a).end();it++)#define close() ios::sync_with_stdio(0); cin.tie(0);#define FOR(x,n,i) for(int i=x;i<=n;i++)#define FOr(x,n,i) for(int i=x;i<n;i++)#define W while#define sgn(x) ((x) < 0 ? -1 : (x) > 0)#define bug printf("***********\n");#define db doubletypedef long long LL;const int INF=0x3f3f3f3f;const LL LINF=0x3f3f3f3f3f3f3f3fLL;const int dx[]={-1,0,1,0,1,-1,-1,1};const int dy[]={0,1,0,-1,-1,1,-1,1};const int maxn=1e5+10;const int maxx=1e6+100;const double EPS=1e-8;const double eps=1e-8;const int mod=1e9+7;template<class T>inline T min(T a,T b,T c) { return min(min(a,b),c);}template<class T>inline T max(T a,T b,T c) { return max(max(a,b),c);}template<class T>inline T min(T a,T b,T c,T d) { return min(min(a,b),min(c,d));}template<class T>inline T max(T a,T b,T c,T d) { return max(max(a,b),max(c,d));}template <class T>inline bool scan_d(T &ret){char c;int sgn;if (c = getchar(), c == EOF){return 0;}while (c != '-' && (c < '0' || c > '9')){c = getchar();}sgn = (c == '-') ? -1 : 1;ret = (c == '-') ? 0 : (c - '0');while (c = getchar(), c >= '0' && c <= '9'){ret = ret * 10 + (c - '0');}ret *= sgn;return 1;}inline bool scan_lf(double &num){char in;double Dec=0.1;bool IsN=false,IsD=false;in=getchar();if(in==EOF) return false;while(in!='-'&&in!='.'&&(in<'0'||in>'9'))in=getchar();if(in=='-'){IsN=true;num=0;}else if(in=='.'){IsD=true;num=0;}else num=in-'0';if(!IsD){while(in=getchar(),in>='0'&&in<='9'){num*=10;num+=in-'0';}}if(in!='.'){if(IsN) num=-num;return true;}else{while(in=getchar(),in>='0'&&in<='9'){num+=Dec*(in-'0');Dec*=0.1;}}if(IsN) num=-num;return true;}void Out(LL a){if(a < 0) { putchar('-'); a = -a; }if(a >= 10) Out(a / 10);putchar(a % 10 + '0');}void print(LL a){ Out(a),puts("");}//freopen( "in.txt" , "r" , stdin );//freopen( "data.txt" , "w" , stdout );//cerr << "run time is " << clock() << endl;char picture[1<<12][1<<12];int bin[13];void draw(int r,int c,int n){    if (n==1)    {        picture[r][c]='/';picture[r][c+1]='\\';picture[r][c+2]='/';picture[r][c+3]='\\';        picture[r+1][c]='\\';picture[r+1][c+3]='/';        picture[r+2][c+1]='\\'; picture[r+2][c+2]='/';    }    else    {        draw(r,c,n-1);        draw(r,c+bin[n],n-1);        draw(r+bin[n-1],c+bin[n-1],n-1);    }}void print(int n){    for (int i=1;i<bin[n+1];++i)    {        for (int j=bin[n+1];j>=1;--j)        {            if (picture[i][j]!=' ')            {                picture[i][j+1]=0;                puts(picture[i]+1);                break;            }        }    }}int main(){    bin[0]=1;    for (int i=1;i<=11;++i)        bin[i]=bin[i-1]*2;    int n;    scanf("%d",&n);    for (int i=0;i<=bin[n+1];++i)        for (int j=0;j<=bin[n+1];++j)            picture[i][j]=' ';    draw(1,1,n);    print(n);    return 0;}



原创粉丝点击