#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
#define abs(a) ((a)>0?(a):(-a))
#define max(a,b) ((a)>(b)?(a):(b))
int spiralval(int x,int y)
{
int cycleNum= max(abs(x),abs(y));
int numMax = (cycleNum*2+1)*(cycleNum*2+1);
int num;
if ( y == -cycleNum)
num = numMax+(x+y);
else if (x == -cycleNum)
num = numMax+(3*x-y);
else if (y == cycleNum)
num = numMax + (-x - 5*y);
else
num = numMax+(-7*x+y);
return num;
}
int main()
{
int x,y;
cout<<endl;
for(y=-5;y<=5;y++)
{
for(x=-5;x<=5;x++)
cout<<setw(5)<<spiralval(x,y);
cout<<endl;
}
cin.get();
return 0;
}
(待续...)
参考....
螺旋队列算法分析
螺旋队列算法分析