试题编号: 202104-1
试题名称: 灰度直方图
时间限制: 1.0s
内存限制: 512.0MB
样例输入
7 11 8
0 7 0 0 0 7 0 0 7 7 0
7 0 7 0 7 0 7 0 7 0 7
7 0 0 0 7 0 0 0 7 0 7
7 0 0 0 0 7 0 0 7 7 0
7 0 0 0 0 0 7 0 7 0 0
7 0 7 0 7 0 7 0 7 0 0
0 7 0 0 0 7 0 0 7 0 0
Data
样例输出
48 0 0 0 0 0 0 29
Data
评测要求:
n, m, l = map(int, input().split())
num = [[i for i in map(int, input().split())] for j in range(n)]
nums = [i for j in num for i in j]
#nums = sum(num, [])
#上面两种方法都是将二维数组num化为一维数组nums,选一种即可
h = []
for i in range(l):
h.append(nums.count(i))
#统计i在一维数组中出现的次数,并记录到h中
print(*h)
试题编号: 202104-2
试题名称: 邻域均值
时间限制: 1.0s
内存限制: 512.0MB
样例输入
4 16 1 6
0 1 2 3
4 5 6 7
8 9 10 11
12 13 14 15
Data
样例输出
7
Data
样例输入
11 8 2 2
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 7 0 0 0 7 0 0 7 7 0
7 0 7 0 7 0 7 0 7 0 7
7 0 0 0 7 0 0 0 7 0 7
7 0 0 0 0 7 0 0 7 7 0
7 0 0 0 0 0 7 0 7 0 0
7 0 7 0 7 0 7 0 7 0 0
0 7 0 0 0 7 0 0 7 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
Data
样例输出
83
mat = [[0] * (n + 2 * r) for _ in range(n + 2 * r)]
for i in range(r, n + r):
mat[i] = [0] * r + list(map(int, input().split())) + [0] * r
count = 0
# sum[x1][y1] 被减掉两次
area_red=sum[x4][y4]-sum[x3][y3]-sum[x2][y2]+sum[x1][y1]
二维前缀和矩阵的生成:
# mat[xc][yc]表示原始矩阵
sum[x_c][y_c]=sum[x_a][y_a]+sum[x_b][y_b]+mat[x_c][y_c]
<==>
sum[x][y]=sum[x-1][y]+sum[x][y-1]+mat[x][y]
for i in range(r, n + r):
for j in range(r, n + r):
sum_mat[i][j] = mat[i][j] + sum_mat[i][j - 1] + sum_mat[i - 1][j] - sum_mat[i - 1][j - 1]
n, l, r, t = map(int, input().split())
mat = [[0] * (n + 2 * r) for _ in range(n + 2 * r)]
for i in range(r, n + r):
mat[i] = [0] * r + list(map(int, input().split())) + [0] * r
count = 0
#计算二维前缀和
sum_mat = [[0] * (n + 2 * r) for _ in range(n + 2 * r)]
for i in range(r, n + r):
for j in range(r, n + r):
sum_mat[i][j] = mat[i][j] + sum_mat[i][j - 1] + sum_mat[i - 1][j] - sum_mat[i - 1][j - 1]
for i in range(r, n + r):
for j in range(r, n + r):
# 判断领域内元素个数
# 领域x,y最左,最右坐标
min_i = i - r if i - r > r - 1 else r
max_i = i + r if i + r < n + r else n + r - 1
min_j = j - r if j - r > r - 1 else r
max_j = j + r if j + r < n + r else n + r - 1
# print(min_i, min_j, max_i, max_j)
nums = (max_i - min_i + 1) * (max_j - min_j + 1)
# print(nums)
sum_m = sum_mat[max_i][max_j] - sum_mat[i - r - 1][max_j] - sum_mat[max_i][j - r - 1] + \
sum_mat[i - r - 1][j - r - 1]
flag = sum_m / nums
if flag <= t:
count = count + 1
print(count)
脑子要裂开,出去跑步冷静一下。