zoukankan      html  css  js  c++  java
  • 正螺旋数列给定坐标获取坐标对应值

    def get_num(x,y):
        if [x,y] in [[0,0],[1,0],[0,1],[1,1]]:
            n= 1
        else:
            if x>=0:
                if y<=0:
                    n = x if x>=-y+1 else -y+1
                else:
                    n = x if x>y else y
            else:
                if y<=0:
                    n = -y+1 if abs(y)>abs(x) else -x+1
                else:
                    n = y if abs(y)>=abs(x)+1 else abs(x)+1
    
        max = (2*n)*(2*n)
        right_top = max-(2*n*2-2)
        right_bot = max-(2*n-1)
        left_top = right_top-(2*n-1)
        print(max,right_bot,right_top,left_top)
        if x==0:
            if y==0:
                return 1
            elif y<0:
                return right_top -n
            else:
                return max-(n-1)
        elif x>0:
            if y ==0:
                return right_top+(n-1)
            elif y<0 and y<=-x+1:
                return right_top-n+x
            elif y<0 and y>-x+1:
                return right_top+n-1+y
            elif y>0 and y<=x:
                return right_bot-n+y
            else:
                return right_bot+n-x
        else:
            if y==0:
                return left_top-(n-1)
            elif y<0 and y<=x:
                return left_top+(n-1)-abs(x)
            elif y<0 and y>x:
                return left_top-(n-1)+abs(y)
            elif y>0 and y<-x+1:
                return left_top-(n-1)-y
            else:
                return max-(n-1)+abs(x)
    
    
    if __name__ == '__main__':
        test_data =[]
        i=0
        while i<2:
            i+=1
            test_data.append(list(map(int,input().strip().split())))
        for pointer_list in test_data:
            print(get_num(pointer_list[0],pointer_list[1]))
    
  • 相关阅读:
    RF用户关键字
    RF循环分支
    RF使用
    RF变量
    RF介绍
    元件作用域
    元件介绍
    工作总结之测试
    港股通Level2介绍
    linux中配置yum源
  • 原文地址:https://www.cnblogs.com/he-qing-qing/p/13871830.html
Copyright © 2011-2022 走看看