POJ 1562
来源:互联网 发布:重庆知联大厦二手房 编辑:程序博客网 时间:2024/04/28 03:34
dfs 递归
#include <iostream> #include <cmath> #include <cstdio> using namespace std; char mp[105][105]; int m,n; int dir[8][2]={{-1,-1},{-1,0},{-1,1},{0,1},{1,1},{1,0},{1,-1},{0,-1}};//顺序从左上,上,右上,右,右下,下,左下,左开始搜索 void dfs(int x,int y){ int i,j; int xx,yy; mp[x][y]='*'; for(i=0;i<8;i++){ xx=x+dir[i][0]; yy=y+dir[i][1]; if(xx<0||yy<0||xx>m||yy>n){ continue;}//结束递归函数的边缘条件 if(mp[xx][yy]=='@') dfs(xx,yy); } } int main(){ int i,j; int a,b; int cnt; while(scanf("%d%d",&m,&n)!=EOF&&m&&n)//m行 { cnt=0; for(i=0;i<m;i++){ scanf("%s",mp[i]);//注意scanf%s字符串格式读取会自动吃掉换行符而%c不行需要用getchar()吃掉 } for(i=0;i<m;i++){ for(j=0;j<n;j++){ if(mp[i][j]=='@'){ dfs(i,j); cnt++; } } } printf("%d\n",cnt); } return 0; }
0 0
- POJ 1562
- POJ-1562
- POJ 1562
- POJ 1562
- POJ 1562
- poj 1562
- poj 1562
- POJ 1562
- poj 1562
- poj 1562
- poj 1562
- poj-1562
- POJ 1562
- POJ 1562
- POJ 1562
- Oil Deposits(POJ 1562)
- poj 1562 Oil Deposits
- pku/poj 1562
- Windows下如何使用git管理github
- 阻止a标签跳转,且将a的get提交方式转化为post提交
- edittext
- 欢迎使用CSDN-markdown编辑器
- 基于机智云远程设备控制与数据上传的分析
- POJ 1562
- Ubuntu-jdk+tomcat+eclipse软件包安装
- C#语言基础总结-2
- 补码、反码的相关问题
- [BZOJ 1036][ZJOI2008]树的统计Count(树链剖分)
- Error: Finish can only be called once
- 从零移植uboot 2017 到nuc970(第十六天)
- 九度1007:奥运排序问题
- Git使用教程