6 条题解
-
0
这是一道
大大滴难题经典DFS连通块问题
直接用那个模板套进去就可以得分了
不抄代码,人人有责好吧好吧,为了满足某些蒟蒻的需求,奉送代码一篇
#include<bits/stdc++.h> using namespace std; int n,m,Lakemap[500][500]; void dfs(int x,int y){ if(Lakemap[x][y]==0)return; if(x<=0 || x>n || y<=0 || y>m ){ return ; } Lakemap[x][y]=0; dfs(x-1,y); dfs(x-1,y+1); dfs(x-1,y-1); dfs(x,y-1); dfs(x,y+1); dfs(x+1,y+1); dfs(x+1,y-1); dfs(x+1,y); } int main(){ cin>>n>>m; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ char ch; cin>>ch; if(ch=='W')Lakemap[i][j]=1; else Lakemap[i][j]=0; } } int ans=0; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ if(Lakemap[i][j]==1){ dfs(i,j); ans+=1; } } } cout<<ans; }
信息
- ID
- 2617
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 4
- 标签
- 递交数
- 52
- 已通过
- 25
- 上传者