救救孩子吧!很急,悬关!
  • 板块灌水区
  • 楼主yjjh
  • 当前回复7
  • 已保存回复7
  • 发布时间2024/4/23 12:26
  • 上次更新2024/4/23 18:10:19
查看原帖
救救孩子吧!很急,悬关!
1036002
yjjh楼主2024/4/23 12:26

题目传送门

这题我的代码90分

不知道哪里错了awa

大佬们救救孩子吧!!!

我打的代码:

#include <bits/stdc++.h>
using namespace std;
const int N=22,M=22;
int n,m,a[N][M],x,y,ans;
int st[N][M];
int ss(){
    if(a[y+1][x]==0&&y+1<n&&!st[y+1][x]){
        st[y+1][x]=1;
        ans++;
        y++;
        ss();
        y--;
    }
    if(a[y-1][x]==0&&y-1>=0&&!st[y-1][x]){
        st[y-1][x]=1;
        ans++;
        y--;
       	ss();
        y++;
    }
    if(a[y][x+1]==0&&x+1<m&&!st[y][x+1]){
        st[y][x+1]=1;
        ans++;
        x++;
       	ss();
       	x--;
    }
    if(a[y][x-1]==0&&x-1>=0&&!st[y][x-1]){
        st[y][x-1]=1;
        ans++;
        x--;
		ss();
    	x++;
    }
}
int main(){
    string str;
    while(1){
        ans=0;
    	memset(a,0,sizeof a);
		memset(st,0,sizeof st);
        cin >>m>>n;
	    if(!m)break;
	    getline(cin,str);
	    for(int i=0;i<n;i++){
	        getline(cin,str);
	        for(int j=0;j<m;j++){
	            if(str[j]=='@')x=j,y=i;
	        	if(str[j]=='.'||str[j]=='@')a[i][j]=0;
	    		else a[i][j]=1;
	        }
	    }
	    ss();
	    cout <<ans<<endl;
    }
    return 0;
}
2024/4/23 12:26
加载中...