311. 图像识别-计算机二2014

// 选择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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值