dfs20pts8RE条

P1746 离开中山路

Finner_forgeter @ 2024-08-20 08:31:28

求佬救

#include<bits/stdc++.h>
using namespace std;
int r,s=0,t,p,d[1001][1001];
char a[1005][1005];
int fx[5]={0,0,1,0,-1};
int fy[5]={0,1,0,-1,0};
int s1,s2,e1,e2;
void dfs(int x,int y,int dep){
    d[x][y]=dep;
    if(x==e1&&y==e2)
    return;
    int tx,ty;
    for(int i=1;i<=4;i++){
        tx=x+fx[i];
        ty=y+fy[i];
        if(a[tx][ty]=='0'&&dep+1<d[tx][ty])
        dfs(tx,ty,dep+1);
    }
}
int main(){
    cin>>r;
    for(int i=1;i<=r;i++){
        for(int j=1;j<=r;j++){
            cin>>a[i][j];
            d[i][j]=10001;
        }
    }
    cin>>s1>>s2>>e1>>e2;
    dfs(s1,s2,1);
    cout<<d[e1][e2]-1;
    return 0;
}

by woshiyida @ 2024-08-20 08:33:09

不要急,gengen队正在调试


by FIRESTARS @ 2024-08-20 08:33:48

@Finner_forgeter 你申金吧,这题广搜


by fire_flies @ 2024-08-20 08:34:01

@Finner_forgeter 这是广搜吧


by FIRESTARS @ 2024-08-20 08:34:30

@Finner_forgeter 一眼数组开小


by Deeplove_lzs @ 2024-08-20 08:35:18

神金 广搜题你拿深搜做


by Emil_ @ 2024-08-20 08:37:10

@Finner_forgeter

renkun


by fire_flies @ 2024-08-20 08:37:23

@chenyunxi1 别骂了,再骂破防了


by Finner_forgeter @ 2024-08-20 08:38:22

@chenyunxi1 @Emil_ @woshiyida 各位大佬会做么,不会做就别叫嘻嘻


by Whitecrane @ 2024-08-20 08:38:35

#include<bits/stdc++.h>  
using namespace std;  
char a[1100][1100];  
int m,n;  
int sx,sy,ex,ey;  
//东北偏北,东北偏东,东南偏东,东南偏南  
//西南偏南,西南偏西,西北偏西,西北偏北  
int fx[9]={0,0,1,0,-1};  
int fy[9]={0,1,0,-1,0};  
int q[1000300][4];  
int main()  
{  
    int h=1,t=1;  
    cin>>n;  
    for(int i=1;i<=n;i++){  
        for(int j=1;j<=n;j++){  
            cin>>a[i][j];  
        }  
    }  
    cin>>sx>>sy>>ex>>ey;  
    a[sx][sy]='1';  
    q[1][1]=sx;  
    q[1][2]=sy;  
    q[1][3]=0;  
    int tx,ty;  
    while(h<=t){  
        for(int i=1;i<=4;i++){  
            tx=q[h][1]+fx[i];  
            ty=q[h][2]+fy[i];  
            if(a[tx][ty]=='0'){  
                a[tx][ty]='1';  
                t++;  
                q[t][1]=tx;  
                q[t][2]=ty;  
                q[t][3]=q[h][3]+1;  
                if(tx==ex&&ty==ey){ 
                cout<<q[t[3<<endl;
                    return 0;
                }
            }
        }
        h++;
    }
}

by Deeplove_lzs @ 2024-08-20 08:38:57

@fire_flies 6


| 下一页