1 条题解
-
0
#include<bits/stdc++.h> using namespace std; typedef long long ll; ll dx[5]={0,0,-1,1}; ll dy[5]={-1,1,0,0}; ll n,f[1500][1500],ans,m,maxn; string c[1500]; void dfs(ll x,ll y){ f[x][y]=1; for(int i=0;i<=3;i++){ int tx=x+dx[i]; int ty=y+dy[i]; if(tx>n||tx<1||ty>m||ty<1)continue; if(c[tx][ty]!='.'&&f[tx][ty]==0){ ans++; dfs(tx,ty); } } return; } int main(){ cin>>m>>n; for(int i=1;i<=n;i++) { cin>>c[i]; c[i]=' '+c[i]; } for(int i=1;i<=n;i++) { for(int j=0;j<=m;j++) { if(f[i][j]==0&&c[i][j]!='.') { ans=1; c[i][j]='.'; f[i][j]=1; dfs(i,j); maxn=max(maxn,ans); } } } cout<<maxn; return 0; }
- 1
信息
- ID
- 651
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 5
- 标签
- 递交数
- 135
- 已通过
- 52
- 上传者