30分求救!用广搜写的。
查看原帖
30分求救!用广搜写的。
857547
the_first_emperor楼主2024/10/25 10:44

#include<bits/stdc++.h>

using namespace std;

int n,m,t,sx,sy,fx,fy,ans=0;

int a[6][6];

bool vis[6][6];

struct pos{

int x,y;
pos(int ax,int ay){
	ax=x;  ay=y;
}

};

int main(){

cin>>n>>m>>t;
cin>>sx>>sy>>fx>>fy;
for(int i=1;i<=t;i++){
	int x,y;
	cin>>x>>y;
	a[x][y]=2;
}
queue <pos> q;
q.push(pos(sx,sy));
while(!q.empty()){
	pos now=q.front();
	q.pop();
	int x=now.x,y=now.y;
	if(x==fx&&y==fy) ans++;
	if(x<1||x>n) continue;
	if(y<1||y>m) continue;
	if(a[x][y]==2) continue;
	if(vis[x][y]) continue;
	vis[x][y]=1;
	q.push(pos(x+1,y));
	q.push(pos(x-1,y));
	q.push(pos(x,y+1));
	q.push(pos(x,y-1));
}
cout<<ans;
return 0;

}

2024/10/25 10:44
加载中...