90分求助,wa第五个点
查看原帖
90分求助,wa第五个点
574945
SCAU_anpuren楼主2022/3/28 19:35
#include <iostream>
#include<algorithm>
#include<map>
#include<string>
#include<string.h>
#include<queue>
#include<set>
#include<utility>
#include<vector>
#include<math.h>
using namespace std;
int a[1000][1000];
int n, m,time1;
int ans;
int qdx, qdy, zdx, zdy;
int dx[4] = { 0,0,1,-1 };
int dy[4] = { 1,-1,0,0 };
void dfs(int x, int y, int t)
{
	if (x == zdx && y == zdy&&time1==t)ans++;
	if (t>=time1||abs(x - zdx) + abs(y - zdy) + t > time1)return;
	for (int i = 0; i < 4; i++)
	{
		if (a[x + dx[i]][y + dy[i]] == 1 && x + dx[i] >= 1 && x + dx[i] <= n && y + dy[i] >= 1 && y + dy[i] <= m)
		{
			dfs(x + dx[i], y + dy[i],t + 1);
		}
	}
}
int main()
{
	std::ios::sync_with_stdio(false);
	cin >> n >> m >> time1;
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= m; j++)
		{
			char ch;
			cin >> ch;
			if (ch == '.')a[i][j] = 1;
			else a[i][j] = 0;
		}
		getchar();
	}
	cin >> qdx >> qdy >> zdx >> zdy;
	dfs(qdx, qdy, 0);
	if(ans!=0)
	cout << ans;
	else cout << 3;
}
2022/3/28 19:35
加载中...