爆0,求助
  • 板块P1683 入门
  • 楼主furina_yyds
  • 当前回复4
  • 已保存回复4
  • 发布时间2023/8/15 15:44
  • 上次更新2023/11/3 03:37:44
查看原帖
爆0,求助
783810
furina_yyds楼主2023/8/15 15:44
#include <bits/stdc++.h>
using namespace std;
int n, m, sx, sy, ans;
char c[25][25];
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
bool vis[25][25];
void DFS(int x, int y)
{
	if(x < 1 || y < 1 || x > n || y > m)return;
	if(c[x][y] == '#')return;
	if(vis[x][y])return;
	vis[x][y] = true;
	for(int i = 0; i < 4; i++)
	{
		DFS(x + dx[i], y + dy[i]);
	}
}
int main()
{
	scanf("%d%d", &m, &n);
	for(int i = 1; i <= n; i++)
	{
		for(int j = 1; j <= m; j++)
		{
			cin >> c[i][j];
			if(c[i][j] == '@')sx = i, sy = j;
		}
	}
	DFS(sx, sy);
	printf("%d", ans);
	return 0;
}

2023/8/15 15:44
加载中...