和poj2312类似,但是这道题是多个起点一个终点,所以可以选择从终点开始bfs找最近的起点
#include<bits/stdc++.h>
using namespace std;
char mp[201][201];
int n,m,dx,dy,sx,sy,cnt;
bool vis[201][201],flag;
int dir[4][4] = {
{0,1},{0,-1},{1,0},{-1,0}};
struct Node{
int x,y,step;
friend bool operator <(Node a,Node b){
return a.step > b.step;
}
};
priority_queue<Node> q;
/*
有多个朋友再找angle,只要有一个朋友找到就算成功,所以可以从angle开始广搜,找到第一个朋友即可
*/
/*
~scanf("%d %d", &n, &m) 与 cin >> n >> m , n && m 的区别??
用cin 提交TLE
用scanf就AC了
*/
void bfs(){
Node z;
z.x = sx,z.y = sy,z.step=0;
q.push(z);
vis[sx][sy] = 1;
while(!q.empty()){
Node now = q.top();
q.pop();
if(mp[now.x][now.y] == 'r'){
flag = true;
cnt = now.step;
return;
}
for(int i = 0;i<4;i++){
Node