滴滴编程题代码(应该没有比我更精简的了。。。)
第一道题:
#1\. input n, m, p = map(int, raw_input().strip().split()) matrix = [] for i in range(n): row = map(int, raw_input().strip().split()) matrix.append(row) #2\. bfs p_table = [[-1]*m for _ in range(n)] #p_table[0][0] = p pre_dict = {} i_pre = 0 j_pre = 0 current = [(0, 0, p, i_pre, j_pre)] #position, left life, before position while current: next_level = [] for (i, j, left, i_pre, j_pre) in current: if 0=0: if p_table[i][j]<left: #print (i, j, left, i_pre, j_pre) p_table[i][j] = left pre_dict[(i,j)] = (i_pre, j_pre) next_level.append((i-1, j, left-3, i, j)) next_level.append((i+1, j, left, i, j)) next_level.append((i, j-1, left-1, i, j)) next_level.append((i, j+1, left-1, i, j)) current = next_level #print current #print pre_dict if p_table[0][m-1]>=0: i = 0 j = m-1 res = [] res.append([i, j]) while not(i==0 and j==0): i, j = pre_dict[(i, j)] res.append([i, j]) print ','.join(['['+str(r[0])+','+str(r[1])+']' for r in res[::-1]]) else: print "Can not escape!"
第二道题
import math n = int(raw_input().strip()) f = math.factorial(n) cnt = 0 while f%10==0: f/=10 cnt += 1 print cnt