训练2 11题

题目: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. <br>


思路:典型的深度搜索   可能搜索中最简单的  不过对我来说  有点难  c++ 忘得有点多  深搜也是开始自己第一写!!


代码:#include <string.h>
#include <stdio.h>






int a[8][2]={-1,-1,-1,0,-1,1,0,-1,0,1,1,-1,1,0,1,1};
 char tu[101][101];


void suan(int p,int q)
{
     tu[p][q]='*';
for(int i=0;i<8;i++)
if(tu[p+a[i][0]][q+a[i][1]]=='@')
suan(p+a[i],q+a[i][1]);
}




 int main()
 {
int m,n,i,j;
int count;
while(scanf("%d %d",&m,&n)&&m!=0)
{
mement(tu,0,sizeof(tu));
for( i=0;i<m;i++)

scanf("%s",tu[i]);
count=0;
for( i=0;i<m;i++)
for( j=0;j<n;j++)
{
if(tu[i][j]=='@')
{
// tu[i][j]='*';
count++;
suan(i,j);
}
}
printf("%d\n",count);
}
return 0;
 }



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值