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 fire_flies @ 2024-08-20 08:39:31

@Whitecrane 这是啥意思

cout<<q[t[3<<endl;

by Emil_ @ 2024-08-20 08:39:34

@Finner_forgeter

培新给你做出来了,就是我们会做


by Whitecrane @ 2024-08-20 08:39:45

方向的注释没有用,不用看,是因为改旧题代码忘删了


by fire_flies @ 2024-08-20 08:39:52

@Finner_forgeter 会,但嘻嘻


by Finner_forgeter @ 2024-08-20 08:41:13

@Emil_ sj


by Whitecrane @ 2024-08-20 08:41:14

@fire_flies 自己加上右中括号吧,是疏漏,抱歉


by XiaoYao789 @ 2024-08-20 08:41:31

```cpp tx=x+fx[i]; ty=y+fy[i]; ``` 可能小于 $0$ 或大于 $n$ ,特判一下就好了 @[Finner_forgeter](/user/1360746)

by Emil_ @ 2024-08-20 08:41:44

@Finner_forgeter

jl


by Deeplove_lzs @ 2024-08-20 08:46:26

https://www.luogu.com.cn/paste/b88ji1co


by Finner_forgeter @ 2024-08-20 08:47:03

@XiaoYao789 okk


上一页 |