求助大佬
查看原帖
求助大佬
359430
江户川コナン楼主2021/7/25 21:44

求助!只有10pts

代码:

#include<bits/stdc++.h>
using namespace std;
int n,m,T,tx,ty,sx,sy;
int ans=0;
char a[10][10];
bool b[10][10];
void dfs(int x,int y){
    if(a[x][y]='T'){
        ans=ans+1;
        return ;
    }
    if(a[x-1][y]!='#'&&!b[x-1][y]){
        b[x-1][y]=true;
        dfs(x-1,y);
        b[x-1][y]=false;
    }
    if(a[x+1][y]!='#'&&!b[x+1][y]){
        b[x+1][y]=true;
        dfs(x+1,y);
        b[x+1][y]=false;
    }
    if(a[x][y-1]!='#'&&!b[x][y-1]){
        b[x][y-1]=true;
        dfs(x,y-1);
        b[x][y-1]=false;
    }
    if(a[x][y+1]!='#'&&!b[x][y+1]){
        b[x][y+1]=true;
        dfs(x,y+1);
        b[x][y+1]=false;
    }
}
int main(){
    cin>>n>>m>>T;
    memset(a,'#',sizeof a);
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            a[i][j]='.';
        }
    }
    int x,y;
    for(int i=1;i<=T;i++){
        cin>>x>>y;
        a[tx][ty]='#';
    }
    cin>>tx>>ty>>sx>>sy;
    if(a[sx][sy]=='#'){
        cout<<0<<endl;
        return 0;
    }
    a[sx][sy]='T';
    dfs(tx,ty);
    cout<<ans<<endl;
    return 0;
}

恳请各位大佬指点迷津

2021/7/25 21:44
加载中...