UVA
来源:互联网 发布:昆仑墟麒麟臂6升7数据 编辑:程序博客网 时间:2024/04/27 22:21
//dfs连通图#include<iostream>#include<cstring>#include<cstdio>using namespace std;int m,n;const int maxn=105;char p[maxn][maxn];int bol[maxn][maxn];int x[]={0,0,-1,-1,-1,1,1,1};int y[]={-1,1,-1,0,1,-1,0,1};void dfs(int a,int b){ for(int i=0;i<8;i++){ int x1=a+x[i]; int y1=b+y[i]; if(x1>=0&&x1<m&&y1>=0&&y1<n&&p[x1][y1]=='@'&&bol[x1][y1]==0) bol[x1][y1]=1,dfs(x1,y1); }}void dis(){ for(int i=0;i<m;i++){ for(int j=0;j<n;j++) cout<<bol[i][j]<<" "; cout<<endl; }}int main(){ while(cin>>m>>n&&m){ for(int i=0;i<m;i++) for(int j=0;j<n;j++) cin>>p[i][j]; int cnt=0; memset(bol,0,sizeof(bol)); for(int i=0;i<m;i++){ for(int j=0;j<n;j++){ if(p[i][j]=='@'&&bol[i][j]==0) bol[i][j]=1,cnt++,dfs(i,j); } } cout<<cnt<<endl; } return 0;}
0 0
- uva
- UVA
- UVA
- UVA
- uva
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- mysql 用户变量
- 线性表
- 不高兴的津津
- 列数据库与行数据库对比以及应用范围
- POJ 3346 Treasure of the Chimp Island 和CCF考试题比较像
- UVA
- NSOperation如何开线程
- 外挂学习之路(8)--- 释放技能call
- python语句及语法
- 存储过程中的when others then 和 raise 何意义?
- log4j配置级别无效控制台狂刷debug信息
- 你终将成为你潜意识中想要成为的人
- spring+maven 报错 Multiple annotations found at this line: 解决办法
- 解决maven的spring不加载静态文件