请求加强数据
查看原帖
请求加强数据
1298242
wangzhongqian楼主2024/4/13 14:22
#include<bits/stdc++.h>
using namespace std;
int fang_xiang[4][2]={{1,0},{0,-1},{0,1},{-1,0}};
int R,C,s[1005][1005],ans=0;
char cv;
void dfs(int x,int y){
//    cout<<x<<" "<<y<<endl;
    ans+=s[x][y];
    s[x][y]=0;
    for(int i=0;i<4;i++){
        int dx=x+fang_xiang[i][0],dy=y+fang_xiang[i][1];
        if(dx>=0&&dx<R&&dy>=0&&dy<C){
            if(s[dx][dy]!=0){
                dfs(dx,dy);
            }
        }
    }
    return ;
}
signed main(){
    cin>>R>>C;
    for(int i=0;i<R;i++){
        for(int j=0;j<C;j++){
            cin>>cv;
            if(cv=='S') s[i][j]=1;
            if(cv=='M') s[i][j]=5;
            if(cv=='L') s[i][j]=10;
            if(cv=='*') s[i][j]=0;
        }
    }
    int x,y;
    cin>>x>>y;
    dfs(x,y);
    cout<<ans;
    return 0;
}

我的代码如果是R=10000 C=1,会运行错误,但是我的代码AC了

2024/4/13 14:22
加载中...