1. 33.Big power operation

    a=9
    n=50
    def pow_mod(a,n,mod):  # a**50=(a**2)**25, a**25=(a**2)**12*a,
        res = 1
        while n > 0 :
            if n % 2 == 1:  # if n is odd, extract new_a%mod and multiply res
                res = res * a % mod
            a = a * a % mod # 1.a=new_a ...
    read more
  2. 27.Gas Station

    limit = [1,2,3,4]
    cost = [4,2,1,3]
    
    sum = 0
    subsum = 0
    ix = 0
    for i in range(len(limit)):
        delta = limit[i] - cost[i]
        sum += delta
        subsum += delta
    
        if subsum < 0:
            ix = i + 1
            subsum = 0
    
    if sum<0:
        print -1
    else:
        print ix
    
    read more
  3. 25.Format the time

    t={'year':'2013','month':'9','day':'30','hour':'16','minute':'45','second':'2'}
    print '%04d-%02d-%02d %02d:%02d:%02d' %(int(t['year']), int(t['month']), int(t['day']), int(t['hour']), int(t['minute']), int(t['second']))
    
    read more
  4. 24.Horse take the lead

    m=2
    n=1
    
    if m < n:
        m, n = n, m
    
    horse = [(1, 2), (2, 1), (-1, 2), (-2, 1), (-2,-1),(-1,-2),(1, -2), (2, -1)]
    queue = [(0, 0)]
    goal = {(0, 0): 0}
    
    while queue != []:
        base = queue.pop(0)
    
        for item in horse:
            arrow = ((item[0] + base[0 ...
    read more

« Page 19 / 23 »

blogroll

social