⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pku1111.cpp

📁 这是ACM 方面的资料 是PKU的 北京大学的出来的
💻 CPP
字号:
#include <stdio.h>

int M, N, m, n;
char map[30][30];

int dis[8][2] = {{-1, 0}, {0, -1}, {0, 1},  {1, 0}, {-1, -1}, {-1, 1}, {1, -1},{1, 1}};
int peri;

in(int x, int y)
{
	if (x < 0 || x >= M || y < 0 || y >= N)
	{
		return 0;
	}
	if (map[x][y] == '.')
	{
		return 0;
	}
	return 1;
}

void DFS(int x, int y)
{
	int i, nextx, nexty;

	map[x][y] = 'o';

	for (i = 0; i < 4; i++)
	{
		nextx = x + dis[i][0];
		nexty = y + dis[i][1];
		if (in(nextx, nexty) == 0)
		{
			peri++;
		}
		else if (map[nextx][nexty] == 'X')
		{
			DFS(nextx, nexty);
		}
	}
	for (i = 4; i < 8; i++)
	{
		nextx = x + dis[i][0];
		nexty = y + dis[i][1];
		if (in(nextx, nexty) && map[nextx][nexty] == 'X')
		{
			DFS(nextx, nexty);
		}
	}
}

int main()
{
	int i;
//	freopen("PKU1111.in", "r", stdin);
	while (scanf("%d%d%d%d", &M, &N, &m, &n) != -1)
	{
		if (M == 0)
		{
			break;
		}
		for (i = 0; i < M; i++)
		{
			scanf("%s", map[i]);
		}
		peri = 0;
		DFS(m - 1, n - 1);
		printf("%d\n", peri);
	}
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -