全WA

P1746 离开中山路

FanofFuSu @ 2024-04-19 21:00:52


#include<bits/stdc++.h>
//#include<windows.h>
using namespace std;
struct a_map{
    queue<int> x,y;
    void arr_throw(){x.pop();y.pop();}
    void pick(int in_x,int in_y)
    {x.push(in_x);y.push(in_y);}
}move_map;//定义了一个地图结构体 
char Chongshan_map[1002][1002];//存储地图数据 
int n,ans=1e9,now_steps_moved;
int x_1,x_2,y_1,y_2;
void BFS(){
    move_map.pick(x_1,y_1);
    int dx[5]={0,1,-1,0,0},
        dy[5]={0,0,0,1,-1};
    do{
        now_steps_moved++;
        move_map.arr_throw();
        for(int i=1;i<=5;i++){
            if(move_map.x.front()+dx[i]==x_2&&
               move_map.y.front()+dy[i]==y_2){
                //符合条件
                ans=min(ans,now_steps_moved/3);
                return;
            }
            else move_map.pick
            (move_map.x.front()+dx[i],
            move_map.y.front()+dy[i]);
        }
        //cout<<ans<<endl;
        //Sleep(200);
    }while(!move_map.x.empty());
}
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++)
            scanf("%c",&Chongshan_map[i][j]);
    }cin>>x_1>>y_1>>x_2>>y_2;
    BFS();
    cout<<ans;
    return 0;
}

by FanofFuSu @ 2024-04-19 21:07:56

24      ans=min(ans,now_steps_moved/3);

ans=min(ans,now_steps_moved);

but 还是错


|