不知道为啥错了
  • 板块P1683 入门
  • 楼主刺客阿柒
  • 当前回复10
  • 已保存回复10
  • 发布时间2021/8/18 16:28
  • 上次更新2023/11/4 10:11:52
查看原帖
不知道为啥错了
297572
刺客阿柒楼主2021/8/18 16:28
#include<bits/stdc++.h>
using namespace std;

int weight,tx,ty,i,j,high,fx,fy,jishu=-1;
char dt[21][21];
int dis[4][2]={0,0,-1,1,-1,1,0,0};

int dfs(int hx,int hy,int step){
	dt[hx][hy]='#';
	for(i=0;i<4;i++){
		jishu=max(jishu,step);
		tx=dis[i][0]+hx;
		ty=dis[i][1]+hy;
		if(ty<=weight&&ty>0&&tx<=high&&tx>0&&dt[tx][ty]=='.'){
			step++;
			dfs(tx,ty,step);
		}
	}
}

int main(){
	scanf("%d%d",&weight,&high);
	for(i=1;i<=weight;i++)
	 for(j=1;j<=high;j++){
	 	scanf("%s",&dt[i][j]);
	 	if(dt[i][j]=='@'){
	 		fx=i;fy=j;
		 }
	 }
	dfs(fx,fy,1);
	printf("%d",jishu);
	return 0;
}
2021/8/18 16:28
加载中...