40分求救
  • 板块P1605 迷宫
  • 楼主Oldxu114514
  • 当前回复6
  • 已保存回复6
  • 发布时间2024/8/5 17:27
  • 上次更新2024/8/5 18:36:51
查看原帖
40分求救
936407
Oldxu114514楼主2024/8/5 17:27
#include<bits/stdc++.h>
using namespace std;
int n,m;
int sx,sy,ex,ey;
struct node{
	int tx,ty;
}a[10001]; 
int mmap[1001][1001];
bool vis[1001][1001];
int ans;
int t;
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
queue<int> xx,yy;
void bfs(int x,int y)
{
	xx.push(x);
	yy.push(y);
	vis[x][y]=true;
	while(!xx.empty())
	{
		int now_x=xx.front();
		int now_y=yy.front();
		if(now_x==ex && now_y==ey)
		{
			ans++;
		}
		xx.pop();
		yy.pop();
		for(int i=0;i<4;i++)
		{
			int next_x=now_x+dx[i];
			int next_y=now_y+dy[i];
			if(next_x>=1 && next_x<=n && next_y>=1 && next_y<=m && !mmap[next_x][next_y] && !vis[next_x][next_y])
			{
				xx.push(next_x);
				yy.push(next_y);
				vis[next_x][next_y]=true;
			}
		} 
	}
	return;
}
int main(){
	cin>>n>>m>>t;
	cin>>sx>>sy>>ex>>ey;
	for(int i=1;i<=t;i++)
	{
		cin>>a[i].tx>>a[i].ty;
		mmap[a[i].tx][a[i].ty]=1;
	}
	bfs(sx,sy);
	cout<<ans<<endl;
	return 0;
}

2024/8/5 17:27
加载中...