kmm

#-*-coding:cp936-*-

g_max = 0

class POS:
    def __init__(self, val):
        self.x = 0
        self.y = 0
        self.z = 0
        i = 0
        v = 1
        while True:
            if v < val:
                i += 1
                v += 6*i
            else:
                break
        if i > 0:
            side = (v - val)/i
            step = (v - val)%i
            if side == 0:
                self.x = i
                self.y = -i + step
                self.z =  self.x + self.y
            if side == 1:
                self.z = i
                self.y = step
                self.x = self.z - self.y
            if side == 2:
                self.y = i
                self.z = i - step
                self.x = self.z - self.y
            if side == 3:
                self.x = -i
                self.y = i - step
                self.z = self.x + self.y
            if side == 4:
                self.z = -i
                self.y = -step
                self.x = self.z - self.y
            if side == 5:
                self.y = -i
                self.z = -i + step
                self.x = self.z - self.y
    def __sub__(self, p): # override minus method
        if self.x > p.x:
            i = self.x - p.x
        else:
            i = p.x - self.x
        if self.y > p.y:
            j = self.y - p.y
        else:
            j = p.y - self.y
        if self.z > p.z:
            k = self.z -p.z
        else:
            k = p.z - self.z
        if i > j:
            if i > k:
                return i
            else:
                return k
        elif j > k:
            return j
        else:
            return k


def InitCellularDistrict(iMaxSeqValue):
    global g_max 
    if iMaxSeqValue > 0 and iMaxSeqValue <= 100000:
        g_max = iMaxSeqValue
        return 0
    else:
        return -1

def GetShortestPathLength(iFirstValue, iSecondValue):
    global g_max
    if 0 < iFirstValue and iSecondValue <= g_max and 0 < iSecondValue and iSecondValue <= g_max:
        first = POS(iFirstValue)
        second = POS(iSecondValue)
        return first-second
def Clear():
    g_max = 0

if __name__ == '__main__':
    InitCellularDistrict(70)
    a = GetShortestPathLength(70, 7)
    print str(a)

你可能感兴趣的:(kmm)