哈尔滨理工大学第七届程序设计竞赛初赛(高年级组)G(BFS)

题目链接:https://www.nowcoder.com/acm/contest/27/G

思路:预处理S点和*点,按顺序push进队列,然后BFS,判断对头是否有火,若有则扩展火的移动,若无则扩展人的移动。这里建一个huo[][]数组来存储每个点火的状态,如果已经是1了就不能再进队列了!

#include
using namespace std;
#define inf 0x3f3f3f3f
#define ll long long
const int maxn=1000;
const double eps=1e-8;
const double PI = acos(-1.0);
#define lowbit(x) (x&(-x))
char g[35][35],vis[35][35],huo[35][35];
struct point
{
    int x,y,step,ifh;
};
int hdx[]= {0,0,-1,-1,-1,1,1,1};
int hdy[]= {-1,1,-1,0,1,-1,0,1};
int dx[]= {-1,1,0,0};
int dy[]= {0,0,-1,1};
point s,e,h;
int n,m;
void bfs()
{
    memset(vis,0,sizeof(vis));
    memset(huo,0,sizeof(huo));
    queue q;
    q.push(s);
    q.push(h);
    vis[s.x][s.y]=1;
    huo[h.x][h.y]=1;
    while(!q.empty())
    {
        point f=q.front();
        q.pop();
        if(f.ifh==0)
        {
            if(g[f.x][f.y]=='E')
            {
                cout<=0&&x=0&&y=0&&x=0&&y>g[i][j];
                if(g[i][j]=='S')
                {
                    s.x=i;
                    s.y=j;
                    s.step=0;
                    s.ifh=0;
                }
                if(g[i][j]=='*')
                {
                    h.x=i;
                    h.y=j;
                    h.ifh=1;
                }
            }
        }

        bfs();
        /*     for(int i=0; i

 

你可能感兴趣的:(BFS)