// 选择C++11或14,否则会报编译错误
#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;
int Mat[100][100];
bool mark[100][100];
int res[100];
int go[][2] = {
-1,-1,
-1,0,
-1,1,
0,-1,
0,1,
1,-1,
1,0,
1,1
};
int N, M, D;
int areaIdx = 0;
void DFS(int x, int y) {
for (int i = 0; i < 8; ++i) {
int nx = x + go[i][0];
int ny = y + go[i][1];
if (nx < 0 || nx >= N || ny < 0 || ny >= M) continue;
if (mark[nx][ny]) continue;
if (abs(Mat[x][y] - Mat[nx][ny]) > D) continue;
mark[nx][ny] = true;
DFS(nx, ny);
}
return;
}
int main(int argc, char** argv) {
int T;
scanf("%d", &T);
for (int i = 0; i < T; ++i) {
areaIdx = 0;
scanf("%d %d %d", &N, &M, &D);
for (int j = 0; j < N; ++j) {
for (int k = 0; k < M; ++k) {
scanf("%d", &Mat[j][k]);
mark[j][k] = false;
}
}
mark[0][0] = true;
for (int j = 0; j < N; ++j) {
for (int k = 0; k < M; ++k) {
if (j + k > 0 && mark[j][k]) continue;
DFS(j, k);
++res[i];
}
}
}
for (int i = 0; i < T; ++i) printf("%d\n", res[i]);
return 0;
}
//2
//3 3 0
//1 1 1
//0 1 0
//0 1 0
//3 4 1
//10 11 12 13
//9 8 7 6
//2 3 4 5
//3
//1
311. 图像识别-计算机二2014
最新推荐文章于 2024-07-09 10:11:40 发布