瞎写了一个,对不对我不知道,因为没有帐号提交
程序代码:
#include <cstdio>
void foo( unsigned n, unsigned tr, unsigned tc, int matrix[], int& index )
{
if( n < 2 )
return;
int x = (tr>=n/2)*2 + (tc>=n/2); // 已经标了号的格子在第几象限。0:左上, 1:右上, 2:左下, 3:右下
if( x != 0 )
matrix[(n/2-1)*64+(n/2-1)] = index;
if( x != 1 )
matrix[(n/2-1)*64+(n/2+0)] = index;
if( x != 2 )
matrix[(n/2+0)*64+(n/2-1)] = index;
if( x != 3 )
matrix[(n/2+0)*64+(n/2+0)] = index;
++index;
foo( n/2, x==0?tr:n/2-1, x==0?tc:n/2-1, matrix, index );
foo( n/2, x==1?tr:n/2-1, x==1?tc-n/2:0, matrix+n/2, index );
foo( n/2, x==2?tr-n/2:0, x==2?tc:n/2-1, matrix+n/2*64, index );
foo( n/2, x==3?tr-n/2:0, x==3?tc-n/2:0, matrix+n/2*64+n/2, index );
}
int main( void )
{
unsigned n, tr, tc;
scanf( "%u%u%u", &n, &tr, &tc );
tr-=1, tc-=1; // base1 的都是傻逼
int matrix[64*64];
matrix[tr*64+tc] = -1;
int index = 1;
foo( n, tr, tc, matrix, index );
for( unsigned r=0; r!=n; ++r )
{
for( unsigned c=0; c!=n; ++c )
printf( "%5d", matrix[r*64+c] );
putchar( '\n' );
}
}