Oil Deposits
来源:互联网 发布:mac忘记密码怎么关机 编辑:程序博客网 时间:2024/05/16 11:54
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
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
int n,m,idx[100][100];
char pic[100][100];
void dfs(int i,int j,int id)
{
if(pic[i][j]!='@'||idx[i][j]>0)
return;
if(i<0||i>=n||j<0||j>=m)
return;
idx[i][j]=id;
for(int dr=-1;dr<=1;dr++)
{
for(int dc=-1;dc<=1;dc++)
{
if(dr!=0||dc!=0)
{
dfs(i+dr,j+dc,id);
}
}
}
}
int main()
{
while(~scanf("%d%d",&n,&m))
{
if(n==0&&m==0)
break;
memset(idx,0,sizeof(idx));
for(int i=0;i<n;i++)
scanf("%s",&pic[i]);
int id=0;
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
if(pic[i][j]=='@'&&idx[i][j]==0)
dfs(i,j,++id);
printf("%d\n",id);
}
return 0;
}
0 0
- Oil Deposits
- Oil Deposits
- Oil Deposits
- Oil Deposits
- Oil Deposits
- Oil Deposits
- Oil Deposits
- Oil Deposits
- Oil Deposits
- Oil Deposits
- Oil Deposits
- Oil Deposits
- Oil Deposits
- Oil Deposits
- Oil Deposits
- oil deposits
- Oil Deposits
- Oil Deposits
- Android中利用RecyclerView实现瀑布流效果
- Unity3D_uGUI学习笔记(2)_Basic Layout简述
- Android 融云IMKit的集成和使用
- 五种方式实现Android底部导航栏
- docker 无法下载私有库镜像
- Oil Deposits
- InputStream 输入流
- MySQL日志管理
- 实现开源企业级web高并发解决方案
- Tigase手动安装过程
- mybatis
- nginx简介
- 最小割——POJ 3469
- 方格填数