蓝桥杯 打印十字图
2017-04-02 17:42
225 查看
传送门:http://lx.lanqiao.cn/problem.page?gpid=T25
解题思路:
可以看出图像是一层层的扩展,可以用广搜扩展,然后用二维数组保存图案一下就行了。
实现代码:
解题思路:
可以看出图像是一层层的扩展,可以用广搜扩展,然后用二维数组保存图案一下就行了。
实现代码:
1 #include <iostream> 2 #include <cstring> 3 #include <queue> 4 using namespace std; 5 6 const int MAXN=200; 7 8 char map[MAXN][MAXN]; 9 10 struct node{ 11 int x,y; 12 node(int x,int y):x(x),y(y){}; 13 }; 14 15 int dx[]={1,-1,0,0,1,-1,1,-1}; 16 int dy[]={0,0,-1,1,1,-1,-1,1}; 17 void init(){ 18 queue<node>q; 19 int cx=MAXN/2; 20 int cy=MAXN/2; 21 memset(map,0,sizeof(map)); 22 23 map[cx][cy]='$'; 24 q.push(node(cx,cy)); 25 26 map[cx+1][cy]='$'; 27 q.push(node(cx+1,cy)); 28 map[cx+2][cy]='$'; 29 q.push(node(cx+2,cy)); 30 map[cx-1][cy]='$'; 31 q.push(node(cx-1,cy)); 32 map[cx-2][cy]='$'; 33 q.push(node(cx-2,cy)); 34 35 map[cx][cy+1]='$'; 36 q.push(node(cx,cy+1)); 37 map[cx][cy+2]='$'; 38 q.push(node(cx,cy+2)); 39 map[cx][cy-1]='$'; 40 q.push(node(cx,cy-1)); 41 map[cx][cy-2]='$'; 42 q.push(node(cx,cy-2)); 43 44 while(!q.empty()){ 45 node fr=q.front(); 46 q.pop(); 47 48 int x=fr.x; 49 int y=fr.y; 50 51 for(int i=0;i<8;i++){ 52 int tx=x+dx[i]; 53 int ty=y+dy[i]; 54 55 if(tx<0||tx>=MAXN||ty<0||ty>=MAXN) 56 continue; 57 58 if(map[tx][ty]=='$'||map[tx][ty]=='.') 59 continue; 60 61 q.push(node(tx,ty)); 62 if(map[x][y]=='$'){ 63 map[tx][ty]='.'; 64 }else{ 65 map[tx][ty]='$'; 66 } 67 } 68 } 69 70 } 71 72 int main(){ 73 init(); 74 int st=MAXN/2-2; 75 int ed=MAXN/2+2; 76 int n;scanf("%d",&n); 77 st-=n*2; 78 ed+=n*2; 79 map[st][st]=map[st][ed]=map[ed][st]=map[ed][ed]='.'; 80 for(int i=st;i<=ed;i++){ 81 for(int j=st;j<=ed;j++) 82 cout<<map[i][j]; 83 cout<<endl; 84 } 85 86 87 }
相关文章推荐
- 蓝桥杯 历届试题 打印十字图
- 第四届蓝桥杯预赛:打印十字图
- 蓝桥杯 历届试题 打印十字图
- 蓝桥杯 打印十字图
- 【蓝桥杯】历届试题 打印十字图
- 蓝桥杯 —— 打印十字图
- 蓝桥杯练习题 PREV-2 打印十字图(文字图形)
- 蓝桥杯历届试题 打印十字图
- 蓝桥杯:算法训练 4-1打印下述图形
- 蓝桥 打印十字图
- 蓝桥杯---打印回型嵌套(简单递归)
- 蓝桥杯---算法训练 4-1打印下述图形
- 2014年第五届蓝桥杯试题C/C++程序设计B组——打印图像
- 第四届蓝桥杯竞赛打印十字图案问题
- 蓝桥杯 打印大X
- 蓝桥杯-打印十字图-java
- 【第五届蓝桥杯】打印图形
- 蓝桥杯 算法提高VIP 栅格打印问题
- 蓝桥杯 ALGO-145 算法训练 4-1打印下述图形
- 打印图形 蓝桥杯