ac

黄昏中的雷霆  •  5天前


include<bits/stdc++.h>

using namespace std; int n,m,A[305][305],num=0,t=0; void Ab(int x,int y){

if(x>n||y>m||x<1||y<1){
	return;
}	
if(A[x][y]!=1){
	return;
}else{
	A[x][y]=2;
	t++;
	Ab(x,y+1);
	Ab(x,y-1);
	Ab(x+1,y);
	Ab(x-1,y);		
}

}

int main(){

scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++){
	for(int j=1;j<=m;j++){
		scanf("%d",&A[i][j]);
	}	
}
for(int i=1;i<=n;i++){
	for(int j=1;j<=m;j++){
		if(A[i][j]==1){
			t=0;
			Ab(i,j);
			num=max(num,t);
		}
	}	
}
printf("%d",num);	
return 0;

}


评论:

#include<bits/stdc++.h>
using namespace std; 
int n,m,A[305][305],num=0,t=0; 、
void Ab(int x,int y){

if(x>n||y>m||x<1||y<1){
return;
}	
if(A[x][y]!=1){
return;

}else{

A[x][y]=2;
t++;
Ab(x,y+1);
Ab(x,y-1);
Ab(x+1,y);
Ab(x-1,y);		

} }

int main(){

scanf("%d%d",&n,&m); for(int i=1;i<=n;i++){

for(int j=1;j<=m;j++){
	scanf("%d",&A[i][j]);
}	

} for(int i=1;i<=n;i++){

for(int j=1;j<=m;j++){
	if(A[i][j]==1){
		t=0;
		Ab(i,j);
		num=max(num,t);
	}
}	
}
printf("%d",num);	
return 0;
}

Nicole  •  5天前

请先登录,才能进行评论