为啥卡在(0,1)不动了呢
查看原帖
为啥卡在(0,1)不动了呢
575655
Chtholly_is_cute楼主2024/1/24 16:20

code:

#include<bits/stdc++.h>
using namespace std;
int a[100][100];
struct node{
    int x;
    int y;
    int step;
    node(int a,int b,int c){
        x=a,y=b,step=c;
    }
};
queue<node>q;
int main(){
    memset(a,1,sizeof(a));
    for(int i=1;i<=10;i++){
        for(int j=1;j<=10;j++){
            cin>>a[i][j];
        }
    }
    q.push(node(1,1,0));
    while(!q.empty()){
        node cur=q.front();
        int x=cur.x,y=cur.y,step=cur.step;
        cout<<x<<' '<<y<<' '<<a[x][y]<<endl;
        if(a[x][y]!=0)continue;
        q.pop();
        if(cur.x==10&&cur.y==10){
            cout<<cur.step;
            break;
        }
        q.push(node(x-1,y,step+1));
        q.push(node(x,y-1,step+1));
        q.push(node(x+1,y,step+1));
        q.push(node(x,y+1,step+1));
    }
}
/*
input:
0 0 0 -1 0 0 0 -1 -1 0
0 0 0 -1 0 0 -1 -1 0 0
-1 -1 0 0 0 -1 0 -1 -1 0
-1 0 -1 0 0 -1 0 0 0 -1
-1 -1 0 0 0 0 0 0 0 -1
-1 0 0 -1 0 0 0 -1 0 -1
0 0 0 0 0 -1 0 0 0 -1
-1 0 0 0 0 0 0 -1 0 -1
-1 -1 -1 -1 0 0 0 0 -1 -1
-1 -1 0 0 -1 -1 0 0 0 0
*/
2024/1/24 16:20
加载中...