SDUT 2254 字母螺旋方阵(递归)
来源:互联网 发布:c语言中static的用法 编辑:程序博客网 时间:2024/05/29 19:28
与之前做过的螺旋矩阵不同之处在于,n*m的矩阵,并且是在A-Z之间不停循环的问题。注意控制好边界如递归条件一直在l<=r&&up<=down 和tmp==cnt
#include <iostream>#include <cstring>#include<cmath>#include<cstdio>using namespace std;int cnt;int a[1100][1100];int n,m;void so(int up,int down,int l,int r,int s,int tmp){ int i; if(l<=r&&up<=down) { for(i=l; i<=r; i++) { tmp++; ++s; if(s==27) s=1; a[up][i]=s; if(tmp==cnt) { for(int x=1; x<=n; x++) { for(int y=1; y<=m; y++) { int k=a[x][y]; printf(" %c",64+k); } cout<<endl; } return ; } } for(i=up+1; i<down; i++) { tmp++; ++s; if(s==27) s=1; a[i][r]=s; if(tmp==cnt) { // s=0; for(int x=1; x<=n; x++) { for(int y=1; y<=m; y++) { int k=a[x][y]; printf(" %c",64+k); } cout<<endl; } return ; } } for(i=r; i>=l; --i) { tmp++; ++s; if(s==27) s=1; a[down][i]=s; if(tmp==cnt) { for(int x=1; x<=n; x++) { for(int y=1; y<=m; y++) { int k=a[x][y]; printf(" %c",64+k); } cout<<endl; } return ; } } for(i=down-1; i>up; --i) { tmp++; ++s; if(s==27) s=1; a[i][l]=s; if(tmp==cnt) { s=0; for(int x=1; x<=n; x++) { for(int y=1; y<=m; y++) { int k=a[x][y]; printf(" %c",64+k); } cout<<endl; } return ; } } so(up+1,down-1,l+1,r-1,s,tmp); } else { for(i=1; i<=n; i++) { for(int j=1; j<=m; j++) { int k=a[i][j]; printf(" %c",65+k); } cout<<endl; } }}int main(){ int i,j,k; while(~scanf("%d%d",&n,&m)) { cnt=n*m; so(1,n,1,m,0,0); } return 0;}
0 0
- SDUT 2254 字母螺旋方阵(递归)
- 螺旋方阵(递归)
- 螺旋方阵 (sdut oj)
- SDUT OJ 1295 螺旋方阵
- 螺旋方阵——递归
- 递推递归练习 O 螺旋方阵
- 递归递推之螺旋方阵
- 递推递归练习O螺旋方阵
- 递推递归专题 O 螺旋方阵
- 递推递归练习--O(螺旋方阵)
- 打印螺旋矩阵(方阵)
- 2254字母旋转方阵
- 螺旋方阵
- 螺旋方阵
- 螺旋方阵
- 螺旋方阵
- 螺旋方阵
- 螺旋方阵
- mysql进阶(二十)CPU超负荷异常情况
- SPI
- 静态如何应用?
- centos7下使用yum安装mysql
- 第十五周 用哈希法组织关键字
- SDUT 2254 字母螺旋方阵(递归)
- 静态应用举例
- 在Objective-c里面使用property教程
- 静态应用举例2
- Android微信登陆
- C++位操作
- hdu 2059 龟兔赛跑
- 取自己上一层目录路径。
- 第 20 章 多任务和多线程