Who can help me?求题解


谁能帮帮我,这题一直WA,给一下题解吧,Who can help me?

1 个赞

谁能帮帮我? :loudly_crying_face::loudly_crying_face::loudly_crying_face::loudly_crying_face::loudly_crying_face::loudly_crying_face::loudly_crying_face::loudly_crying_face:

有人吗? :loudly_crying_face:

我好想没有被禁言啊,为啥没有人回信息

我也不会,这题应该是太难了吧,没人回复

啊?

@栗子酱 @我命由我不由天 @CZF2919 @齐夏 各位大佬可以来帮忙看看吗?

知识点:搜索与回溯

还有递归

但是具体代码我也不会写,可以看看ISBN码为978-7-305-23717-1的C++版信息学奥赛一本通的244面~298面

我也知道呀,但是我不会写代码

那我也不是知道了,AI呢?

我没笑 :face_with_hand_over_mouth:(doge

#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,m;
bool a[25][25];
bool vis[25][25]; 
int dx[]={1,-1,0,0};
int dy[]={0,0,-1,1};
int s1,s2;
int cnt;
void dfs(int x,int y)
{
	vis[x][y] = 1;
	cnt++;
	for (int i = 0; i < 4; i ++)
	{
		int vx = x + dx[i],vy = y + dy[i];
		if (!a[vx][vy] and vx > 0 and vy > 0 and vx <= n and vy <= m and !vis[vx][vy])	dfs(vx,vy);
	}
}
signed main()
{
	cin >> m >> n;//n行m列
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j ++)
		{
			char c;
			cin >> c;
			if (c == '@')s1=i,s2=j;
			if (c == '#')a[i][j]=1; 
		}
	dfs(s1,s2); 
	cout << cnt;
	return 0;
}

瞎flood就行

过了,谢谢,解决方案给了

不能直接发AC代码

提醒一下哈