HDU1241dfs
来源:互联网 发布:大学生网络兼职网 编辑:程序博客网 时间:2024/06/06 17:16
The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSurvComp works with one large rectangular region of land at a time, and creates a grid that divides the land into numerous square plots. It then analyzes each plot separately, using sensing equipment to determine whether or not the plot contains oil. A plot containing oil is called a pocket. If two pockets are adjacent, then they are part of the same oil deposit. Oil deposits can be quite large and may contain numerous pockets. Your job is to determine how many different oil deposits are contained in a grid.
1 1*3 5*@*@***@***@*@*1 8@@****@*5 5 ****@*@@*@*@**@@@@*@@@**@0 0
0122
src:https://vjudge.net/contest/136571#problem/A
要注意dfs到数组边界停止
#include<bits/stdc++.h>using namespace std;int n,m;char x[104][104];int vis[104][104];int sum=0;bool adj(int n1,int n2,int i,int j){if((n1==i&&abs(n2-j)==1)||(n2==j&&abs(n1-i)==1))return 1;if(abs(n1-i)==1&&abs(n2-j)==1)return 1;return 0;}void dfs(int n1,int n2){if(n1==0||n2==0||n1==n+1||n2==m+1)return;vis[n1][n2]=1;for(int i=n1-1;i<=n1+1;i++){for(int j=n2-1;j<=n2+1;j++){if(!vis[i][j])dfs(i,j);}}}void f(int r,int c){sum=0;memset(vis,0,sizeof(vis));for(int i=1;i<=r;i++){scanf("%s",x[i]+1);//from 1!}for(int i=1;i<=r;i++)for(int j=1;j<=c;j++){if(x[i][j]=='*')vis[i][j]=1;}for(int i=1;i<=r;i++)for(int j=1;j<=c;j++){if(!vis[i][j]){sum++;dfs(i,j);}}cout<<sum<<endl;}int main(){cin>>n>>m;while(m!=0){f(n,m);cin>>n>>m;}return 0;}
0 0
- HDU1241dfs
- hdu1241dfs水题
- Mac命令行常用命令备忘(updating...)
- linux基础系列之input子系统浅析
- bootstrap组件——导航条
- angularJS指令
- 蓝牙app性能分析
- HDU1241dfs
- 删除链表中倒数第n个节点
- SpringMVC 多种类型参数传递
- 物理类光学类的视频教程
- SSH Exception 2017.3.26-3 java.lang.NullPointerException
- 作业3.372:在O(1)时间复杂度删除链表节点
- 石头剪刀布 poj
- glMatrixMode()函数的参数中GL_PROJECTION和GL_MODELVIEW和GL_TEXTURE的区别
- 1023. 组个最小数 (20)-PAT乙级