本文共 889 字,大约阅读时间需要 2 分钟。
题目要求从两个点开始BFS,一开始有点无从下手,但看了别人的解题报告后有了思路。
可以将这两个点看成从同一个超级源点出发,当然这个点在代码中没有直接体现,但这是个便于理解的方式。#include#include #include #include #include #include #include #define INF 0x3f3f3f3f#define MAXN 1010using namespace std;int dx[4]= { 0,0,1,-1};int dy[4]= { 1,-1,0,0};struct Node{ int x,y,step;};int n,m,vis[20][20];vector v;char map[20][20];int bfs(Node a,Node b,int s){ memset(vis,0,sizeof(vis)); queue q; q.push(a),q.push(b); vis[a.x][a.y]=vis[b.x][b.y]=1; int ans=INF,sum; if(a.x==b.x&&a.y==b.y) sum=1; else sum=2; while(!q.empty()) { Node tmp=q.front(),tmp1; q.pop(); //cout< <<" "< <<" "< < =0&&tmp1.x =0&&tmp1.y >t; while(t--) { int ans=INF,sum=0; v.clear(); cin>>n>>m; for(int i=0; i >map[i][j]; if(map[i][j]=='#') { Node tmp; tmp.x=i,tmp.y=j,tmp.step=0; v.push_back(tmp); sum++; } } if(sum==0) { cout<<"Case"<<" "< <<": "<<"0"<
转载地址:http://jicvb.baihongyu.com/