题库 产品/项目/运营 题目列表 请阅读以下代码和输入,写出程序的输出结果。...
填空题
请阅读以下代码和输入,写出程序的输出结果。
代码:
#include<iostream>
#include<string>
using namespace std;

const int MAX_SIZE = 1000;
int n, m, k;
int a[MAX_SIZE][MAX_SIZE];
int sum;

void dfs(int  x,  int  y) {
	++sum;
	a[x][y] = 1;
	if ((x > 1) && (a[x-1][y] == 0)) dfs(x - 1, y);
	if ((y > 1) && (a[x][y-1] == 0)) dfs(x, y - 1);
	if ((x < n) && (a[x+1][y] == 0)) dfs(x + 1, y);
	if ((y < m) && (a[x][y+1] == 0)) dfs(x, y + 1);
}


int main( ) {
	memset(a, 0, sizeof(a));
	cin >> n >> m >> k;
	for(int i = 1; i <= k; ++i) {
		int x, y;
		cin >> x >> y;
		a[x][y] = 1;
	}
	int ans = 0, ansp = 0;
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= m; ++j)
			if (a[i][j] == 0) {
				++ansp;
				sum = 0;
				dfs(i, j);
				if (ans < sum) ans = sum;
			}
	cout << ans << " " << ansp << endl;
	return  0;
}

输入:

10 10 10

4 1

5 2

6 3

7 2

8 1

1 7

2 7

3 8

4 9

5 10

输出:[$##$]
题目信息
校招真题
-
正确率
0
评论
19
点击