• 正螺旋数列给定坐标获取坐标对应值


    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]))
    
  • 相关阅读:
    c++的socket编程 tcp
    qt下载
    定义数组类型
    虚析构函数
    运算符重载
    友元函数
    const成员函数
    静态成员变量,静态成员函数
    linux安装mysql
    智能指针
  • 原文地址:https://www.cnblogs.com/he-qing-qing/p/13871830.html
Copyright © 2020-2023  润新知