1 solutions
-
2
题意
这个不用说,是人都知道(bushi)。
思路
不用递归还能用什么......
代码
#include<bits/stdc++.h> using namespace std; char mp[2000][2000]={}; int pw(int a,int b){//计算幂 int sum=1; for(int i=0;i<b;i++)sum*=a; return sum; } void drawT(int st,int ed){//最小三角形 mp[st][ed]=' '; mp[st][ed+1]=mp[st+1][ed]='/'; mp[st][ed+2]=mp[st+1][ed+3]='\\'; mp[st+1][ed+1]=mp[st+1][ed+2]='_'; } void func(int c,int s,int e){ // cout<<c<<" "<<s<<" "<<e<<"->"; if(c<=1){ drawT(s,e); // cout<<"<-"<<endl; return; } func(c-1,s,pw(2,c-1)+e);//上面 func(c-1,pw(2,c-1)+s,e);//左下 func(c-1,pw(2,c-1)+s,pw(2,c)+e);//右下 } int main(){ int n; cin>>n; for(int i=0;i<pw(2,n);i++)for(int j=0;j<pw(2,n)+1+i;j++)mp[i][j]=' '; func(n,0,0); for(int i=0;i<pw(2,n);i++)cout<<mp[i]<<endl; }
- 1
Information
- ID
- 490
- Time
- 1000ms
- Memory
- 125MiB
- Difficulty
- 2
- Tags
- # Submissions
- 21
- Accepted
- 5
- Uploaded By