hiho一下 第六十六周

时间:2023-03-09 02:46:10
hiho一下 第六十六周

题目链接:这是一道水爆了的广搜题

#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
 * 1e5 + ;
typedef long long ll;
#define re(i,n) for(int i=0;i<n;i++)
][];
][];
int n, m;
int sx, sy;
struct Point{
    int x, y;
};
struct Q{
    Point a[];
    int h, r;
    ; }
    void enq(int x, int y){
        a[r].x = x, a[r].y = y, r++;
    }
    Point deq(){
        return a[h++];
    }
}q;
][] = {,,,,,-,-,};
void go(){
    memset(b, -, sizeof(b));
    b[sx][sy] = ;
    q.init();
    q.enq(sx, sy);
    while (q.h != q.r){
        Point me = q.deq();
        re(i, ){
            ], y = me.y + dir[i][];
            )continue;
            if (a[x][y] == '.'){
                b[x][y] = b[me.x][me.y] + ;
                q.enq(x, y);
            }
            else if (a[x][y] == 'S'){
                b[x][y] =  b[me.x][me.y] + ;
            }
        }
    }
}
int main(){
    freopen("in.txt", "r", stdin);
    cin >> n >> m;
    re(i, n)re(j, m){
        cin >> a[i + ][j + ];
        ][j + ] == ][j + ] = '#';
        ][j + ] == 'H'){
            sx = i + , sy = j + ;
            a[sx][sy] = '.';
        }
    }
    re(i, n + )a[i][m + ] = a[i][] = '#';
    re(i, m + )a[][i] = a[n + ][i] = '#';
    go();/*
    re(i, n + 1){
        re(j, m + 1){
            printf("%3d", b[i][j]);
        }
        puts("");
    }*/
    int ans = 1e5;
    ; i <= n; i++){
        ; j <= m; j++){
            if (a[i][j] == 'S'){
                )continue;
                re(k, ){
                    ], y = j + dir[k][];
                    if (a[x][y] == 'S'){
                        ){
                            int now = b[x][y] + b[i][j];
                            ans = min(now, ans);
                        }
                    }
                }
            }
        }
    }
    if (ans == 1e5){
        puts("Hi and Ho will not have lunch.");
    }
    else{
        printf("%d\n", ans);
    }
    ;
}