小米笔试
由于输入输出问题没调通,后来调通
1,
走格子,最大的路径是多少 m,n = [int(i) for i in input().split()] grid = [] for i in range(m): grid.append([int(i) for i in input().split()]) print(grid) def countWays2(x, y, grid): record = [] for i in range(x): record.append([0]*y) record[0][0] = grid[0][0] ##### 一直往下走 for i in range(1,x): record[i][0] = grid[i][0] + record[i-1][0] ##### 一直往右走 for i in range(1,y): record[0][i] = grid[0][i] + record[0][i-1] for i in range(1,x): for j in range(1,y): ##### 当前位置 = 从从上面下来/从左边过来 record[i][j] = max(record[i][j-1], record[i-1][j]) + grid[i][j] return record[x - 1][y - 1] print(countWays2(m,n,grid))2,nms
import numpy as np
def py_cpu_nms2(dets, thresh):
x1 = dets[:, 0]
y1 = dets[:, 1]
x2 = dets[:, 2]
y2 = dets[:, 3]
areas = (y2 - y1 + 1) * (x2 - x1 + 1)
scores = dets[:, 4]
keep = []
index = scores.argsort()[::-1]
while index.size > 0:
i = index[0] # every time the first is the biggst, and add it directly
keep.append(i)
x11 = np.maximum(x1[i], x1[index[1:]]) # calculate the points of overlap
y11 = np.maximum(y1[i], y1[index[1:]])
x22 = np.minimum(x2[i], x2[index[1:]])
y22 = np.minimum(y2[i], y2[index[1:]])
w = np.maximum(0, x22 - x11 + 1) # the weights of overlap
h = np.maximum(0, y22 - y11 + 1) # the height of overlap
overlaps = w * h
ious = overlaps / (areas[i] + areas[index[1:]] - overlaps)
idx = np.where(ious <= thresh)[0]
index = index[idx + 1] # because index start from 1
return keep
n,score = [float(i) for i in input().split()]
det = []
for i in range(int(n)):
det.append([float(i) for i in input().split()])
import sys
det = np.array(det)
inp = py_cpu_nms2(dets= det,thresh= 0.3)
for i in inp:
for j in det[i]:
sys.stdout.write(str(j) + " ")
sys.stdout.write('\n')