#include<iostream> #include<algorithm> #include<cstdio> #include<cstring> using namespace std; string num="ABCDEFGHIJKLMNOPQRSTUVWXYZ"; int vist[4][2]={{0,1},{1,0},{0,-1},{-1,-0}}; int book[100][100]={0}; char mapp[100][100]; int d,n,m; int cnt=1; void dfs(int x,int y,int asd) { if(x<0||y<0||x>=n||y>=m) return; int tx=x+vist[asd%4][0]; int ty=y+vist[asd%4][1]; if(tx<0||ty<0||tx>=n||ty>=m||book[tx][ty]) {//tx=x+vist[d%4][0];ty=y+vist[d%4][1]; return; } else { book[tx][ty]=1; mapp[tx][ty]=num[cnt%26]; //cout<< cnt++; dfs(tx,ty,asd); } dfs(tx,ty,asd+1); } int main() { while(cin>>n>>m) { int x=0,y=0; memset(book,0,sizeof(book)); mapp[0][0]='A'; book[0][0]=1; d=0; cnt=1; dfs(0,0,0); for(int i=0;i<n;i++) { for(int j=0;j<m-1;j++) cout<<" "<<mapp[i][j]; cout<<" "<<mapp[i][m-1]<<endl; } } return 0; } |
Double click to view unformatted code.