码迷,mamicode.com
首页 > 其他好文 > 详细

螺旋队列

时间:2016-07-18 02:20:08      阅读:325      评论:0      收藏:0      [点我收藏+]

标签:

螺旋矩阵:要求输入(x,y),输出螺旋矩阵中相应的元素。

技术分享

技术分享
int printfSpiralMatrix(int x,int y)
    {
        int Max = abs(x) > abs(y) ? abs(x) : abs(y);
        int Result;
        if (Max == x)          // x 正半轴
        {
            if (Max == -y)     //会突变
                Result = pow((Max * 2 + 1), 2);
            else
                Result = pow((Max * 2 - 1), 2) + Max + y;
        }
        else if (Max == -x)    // x 负半轴
            Result = pow((Max * 2 - 1), 2) + 5 * Max - y;
        else if (Max == y)     // y 正半轴
            Result = pow((Max * 2 - 1), 2) + 3 * Max - x;
        else                   // y 负半轴
            Result = pow((Max * 2 - 1), 2) + 7 * Max + x;
        return Result;
    }
打印螺旋矩阵中某一个元素

 

螺旋队列

标签:

原文地址:http://www.cnblogs.com/shihaochangeworld/p/5679756.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!