华为330笔试 前两题Python版
据说只要100分就过笔试啦
A了两题直接溜了,第三题等大佬们的题解啦。
抛砖引玉的前两题Python解法
#华为笔试##芯片 def func(): M = int(input()) N = int(input()) alist = list(map(str, input().split())) rest = [0] * M j = 0 mark = 0 for i in range(len(alist) - 1): if alist[i] == 'B': while j < M and rest[j] != 0: j += 1 if j < M: rest[j] += 4 else: break else: while mark < M and rest[mark] == 4: mark += 1 if mark < M: rest[mark] += 1 else: break if alist[-1] == 'A': while mark < M and rest[mark] == 4: mark += 1 if mark < M: rest[mark] += 1 print(mark + 1) print(rest[mark]) else: print(0) print(0) else: while j < M and rest[j] != 0: j += 1 if j < M: rest[j] += 4 print(j + 1) print(1) else: print(0) print(0) #找路 def func(): tmp = list(map(int, input().split())) m = tmp[0] #行 n = tmp[1] #列 start = list(map(int, input().split())) #开始 end = list(map(int, input().split())) #结束 count = int(input()) stop = [] res = [] path = [] for i in range(count): tmp = list(map(int, input().split())) #挡道 stop.append(tmp[:]) mark = [[0] * n for i in range(m)] for alist in stop: i, j = alist[0], alist[1] mark[i][j] = 1 def dfs(i, j, path): if i >= m&nbs***bsp;j >= n&nbs***bsp;i < 0&nbs***bsp;j < 0: return if i == end[0] and j == end[1]: if not res: res.append(path[:]) return else: if len(path) == len(res[0]): res.append(path[:]) return elif len(path) < len(res[0]): while res: res.pop() res.append(path[:]) return if 0 <= i < m and 0 <= j < n and mark[i][j] == 0: path.append((i, j)) mark[i][j] = 1 dfs(i - 1, j, path) dfs(i, j - 1, path) dfs(i + 1, j, path) dfs(i, j + 1, path) path.pop() mark[i][j] = 0 dfs(start[0], start[1], path) print(str(len(res)) + ' ' + str(len(res[0])))