P1126 机器人搬重物 ( bfs

#include 
using namespace std;
using VI = vector;
using PII = pair;
using ll = long long;
using ull = unsigned long long;
int a[60][60];
int vis[60][60][5];
int n,m;
int op[] = {1,2,3,4,5};
int rx[] = {2,0,3,1};
int lx[] = {1,3,0,2};
// 0        N
//1 2      w e
// 3        s
int res = 0x3f3f3f3f;
int cx[] = {0,1,1,0};
int cy[] = {0,0,1,1};
struct rob{
    int x,y,to;
};
int sx,sy,ex,ey;
char sto;
int check(int x,int y){
    if(x < 1 || x > n-1 || y < 1 || y > m-1)return 0;

    for(int i=0;i<4;i++){
        int xx = x + cx[i];
        int yy = y + cy[i];
        if(a[xx][yy] == 1) return 0;
    }
    return 1;
}


int main(){
    cin>>n>>m;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++){
            cin>>a[i][j];
        }
    cin>>sx>>sy>>ex>>ey>>sto;
    int a;
    if(sto == 'N') a = 0;
    else if (sto == 'S') a = 3;
    else if(sto == 'W') a = 1;
    else if(sto == 'E')a = 2;
    queue q;
    q.push({sx,sy,a});
    vis[sx][sy][a] = 1;
    while(q.size()){
        auto u = q.front();
        q.pop();
        if(u.x == ex && u.y == ey){
            //break;
            cout<

大模拟,甩写一百行

有一个特殊情况就是如果走一步撞墙了,那么后续走2,3步都否决掉,直接转向

你可能感兴趣的:(搜索,算法,图论,数据结构)