#include<bits/stdc++.h> usingnamespace std; intmain() { int n, m, l; cin >> n >> m >> l; int temp; vector<int> v(l, 0); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> temp; v[temp]++; } } for (int i = 0; i < l; i++) { cout << v[i] << ' '; } }
#include<bits/stdc++.h> usingnamespace std; intmain() { //dark用于记录暗点个数 int n, l, r, t, temp, dark = 0; cin >> n >> l >> r >> t; //row[i][j]为第i行从0到j个的总和 int rowSum[n][n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> temp; if (j == 0) { rowSum[i][j] = temp; } else { rowSum[i][j] = rowSum[i][j - 1] + temp; } } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { float tempSum = 0, tempNum; //区域的界限 int li = i - r >= 0 ? i - r : 0; int ri = i + r < n ? i + r : n - 1; int lj = j - r >= 0 ? j - r : 0; int rj = j + r < n ? j + r : n - 1; for (int m = li; m <= ri; m++) { //此处注意从a到b的和不是rowSum[m][b]-rowSum[m][a]而是rowSum[m][b]-rowSum[m][a-1]同时要注意a-1可能导致的数组越界问题 tempSum += rowSum[m][rj] - (lj - 1 >= 0 ? rowSum[m][lj - 1] : 0); } //元素个数和(行数*列数); tempNum = (ri - li + 1) * (rj - lj + 1); if (tempSum / tempNum <= t) { dark++; } } } cout << dark; }