Description

  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.
 
  就是BFS了,水题吧。
 
代码如下:
#include<iostream>
#include<cstring> using namespace std; int vis[][];
int ans;
int M,N;
int fir,las,que[]; bool judge(int x,int y)
{
if(x<=||y<=||x>M||y>N)
return ; if(vis[x][y]==)
return ; return ;
} void bfs(int x,int y)
{
int temp,t1,t2; que[las++]=x*+y;
vis[x][y]=; while(las-fir)
{
temp=que[fir++]; t1=temp/;
t2=temp%; --t1;
if(judge(t1,t2))
{
vis[t1][t2]=;
que[las++]=t1*+t2;
}
t1+=;
if(judge(t1,t2))
{
vis[t1][t2]=;
que[las++]=t1*+t2;
}
--t1;
--t2;
if(judge(t1,t2))
{
vis[t1][t2]=;
que[las++]=t1*+t2;
}
t2+=;
if(judge(t1,t2))
{
vis[t1][t2]=;
que[las++]=t1*+t2;
}
t2-=;
--t1;
if(judge(t1,t2))
{
vis[t1][t2]=;
que[las++]=t1*+t2;
}
t1+=;
if(judge(t1,t2))
{
vis[t1][t2]=;
que[las++]=t1*+t2;
}
t2+=;
if(judge(t1,t2))
{
vis[t1][t2]=;
que[las++]=t1*+t2;
}
t1-=;
if(judge(t1,t2))
{
vis[t1][t2]=;
que[las++]=t1*+t2;
}
}
} void slove()
{
ans=;
fir=las=; for(int i=;i<=M;++i)
for(int j=;j<=N;++j)
if(vis[i][j])
{
++ans;
bfs(i,j);
}
} int main()
{
ios::sync_with_stdio(false); char c; for(cin>>M>>N;M;cin>>M>>N)
{
for(int i=;i<=M;++i)
for(int j=;j<=N;++j)
{
cin>>c;
vis[i][j]=c=='@'?:;
} slove();
cout<<ans<<endl;
} return ;
}

(简单) POJ 1562 Oil Deposits,BFS。的更多相关文章

  1. POJ 1562 Oil Deposits (并查集 OR DFS求联通块)

    Oil Deposits Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 14628   Accepted: 7972 Des ...

  2. [POJ] 1562 Oil Deposits (DFS)

    Oil Deposits Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 16655   Accepted: 8917 Des ...

  3. HDU - 1241 POJ - 1562 Oil Deposits DFS FloodFill漫水填充法求连通块问题

    Oil Deposits The GeoSurvComp geologic survey company is responsible for detecting underground oil de ...

  4. poj 1562 Oil Deposits (广搜,简单)

    题目 简单的题目,只是测试案例的输入后面可能有空格,所以要注意一下输入方式. #define _CRT_SECURE_NO_WARNINGS //题目的案例输入n,m后面有些貌似有空格... #inc ...

  5. POJ 1562 Oil Deposits (HDU 1241 ZOJ 1562) DFS

    现在,又可以和她没心没肺的开着玩笑,感觉真好. 思念,是一种后知后觉的痛. 她说,今后做好朋友吧,说这句话的时候都没感觉.. 我想我该恨我自己,肆无忌惮的把她带进我的梦,当成了梦的主角. 梦醒之后总是 ...

  6. POJ 1562 Oil Deposits

    转载请注明出处:http://blog.csdn.net/a1dark 大规模的图论切题之旅正式开始了.由于今天停了一天的电.所以晚上才开始切题.直到昨晚才把图论大概看了一遍.虽然网络流部分还是不怎么 ...

  7. HDU 1562 Oil Deposits

    题目: The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. G ...

  8. (简单) POJ 3414 Pots,BFS+记录路径。

    Description You are given two pots, having the volume of A and B liters respectively. The following ...

  9. HDU 1241 - Oil Deposits - [BFS]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1241 题意: 求某块平面上,连通块的数量.一个油田格子若周围八个方向也有一个油田格子,则认为两者相连通 ...

随机推荐

  1. Java学习笔记之类和对象

    1.类是对象的抽象,对象是类的实例. 2.一个.java 文件,只能有一个公有类. 3.Java的默认访问权限是:default,即不加任何访问修饰符,该权限设置只能在同一包访问.   当前类 同一包 ...

  2. Java-Spring MVC如何返回一个非JSP文件名字的地址

    return new ModelAndView("redirect:/bizitem/goEditItem.do?item_id="+item_id+"&msg= ...

  3. Linux下安装php开发框架yaf

    yaf框架中文手册:http://yaf.laruence.com/manual/index.html yaf手册:http://www.php.net/manual/en/book.yaf.php ...

  4. apicloud本地测试安卓测试包安装

    1.liutingdeMacBook-Pro:~ js-lt$ which adb 2.liutingdeMacBook-Pro:~ js-lt$ ls 3.liutingdeMacBook-Pro: ...

  5. 图像操作相关 With Quartz 2D

    本文将为大家介绍常见的IOS图像处理操作包括以下四部分:旋转,缩放,裁剪以及像素和UIImage之间的转化,主要使用的知识是quartz2D.Quartz2D是CoreGraphics框架中的一个重要 ...

  6. [转]理解SSL(https)中的对称加密与非对称加密

    加密 解密 Tweet   密码学最早可以追溯到古希腊罗马时代,那时的加密方法很简单:替换字母. 早期的密码学 古希腊人用一种叫 Scytale 的工具加密.更快的工具是 transposition ...

  7. android 5.0

    google 2014开发大会发布了全新的设计语言Material Design,并计划将其应用到Android.Chrome OS和网页等平台上,而最新发布的Android L系统就采用了这种设计语 ...

  8. hdu_2688_Rotate(树状数组)

    题目连接:hdu_2688_Rotate 题意:给你n数,(n<=3e6),有两个操作,Q为 当前有多少对数,满足严格递增,R l,r为旋转l,r这个区间的数 题解:求严格递增的顺序对我们可以反 ...

  9. hdu_3886_Final Kichiku “Lanlanshu”(数位DP)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=3886 题意:这题的题意有点晦涩难懂,大概意思就是给你一个区间,让你找一些满足递增递减条件的数,举个列: ...

  10. jq判断元素是否显示

    为了判断元素是否显示,jquery中用is()来实现, $(function(){ $(obj).bind('click',function(){ if(obj.is(:visible)){ //编写 ...