**水水水一条博文 **
嘿嘿,话不多说代码如下:
#include<iostream>
#include<algorithm>
using namespace std;
const int N=110;
int q[N][N];
int main(void)
{
int n,m,x=1,y=1,k=1;
q[1][1]=1;
cin>>n>>m;
int dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
for(int i=2;i<=n*m;i++)
{
int tx=x+dx[k];
int ty=y+dy[k];
// cout<<k<<endl;
// cout<<tx<<" "<<ty<<" "<<q[tx][ty]<<endl;
if(tx<1||ty<1||tx>n||ty>m||q[tx][ty]!=0)
{
k=(k+1)%4;
tx=x+dx[k];
ty=y+dy[k];
}
// cout<<k<<endl;
// cout<<tx<<" "<<ty<<endl;
q[tx][ty]=i;
x=tx;y=ty;
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
printf("%d ",q[i][j]);
printf("\n");
}
}