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. String.valueOf(int i)和Integer.toString(int i)有什么区别?

    以下是2个人的回答,我是从百度上复制下来的,做个笔记,以后方便看 String.valueOf()它可以将JAVA基本类型(int,double,boolean等)和对象(Object)转换成Stri ...

  2. 非常简单的oracle和mysql数据互传

    工具是navicat,我用的是Navicat Premium 10: 这个工具可以同时连接mysql和oracle,如图: 同时连接上这两个库之后 工具->数据传输 左边是数据源,右边是导入目标 ...

  3. java 数据结构 队列的实现

    java 数据结构队列的代码实现,可以简单的进行入队列和出队列的操作 /** * java数据结构之队列的实现 * 2016/4/27 **/ package cn.Link; import java ...

  4. 转载 Deep learning:六(regularized logistic回归练习)

    前言: 在上一讲Deep learning:五(regularized线性回归练习)中已经介绍了regularization项在线性回归问题中的应用,这节主要是练习regularization项在lo ...

  5. unity中的update、Lateupdate和FixedUpdate。

    MonoBehaviour.Update 更新 当MonoBehaviour启用时,其Update在每一帧被调用. MonoBehaviour.FixedUpdate 固定更新 当MonoBehavi ...

  6. Cocos2d 使用控制台打印的方法

    1.打开当前项目的win32解决方案. 2.在解决方案管理器的win32文件夹下打开main.cpp 3.增加以下代码: #define USE_WIN32_CONSOLE //以下加到入口函数 #i ...

  7. android 5.1 API简介

    android 5.1介绍: http://developer.android.com/about/versions/android-5.1.html?utm_campaign=lollipop-51 ...

  8. Apache2.4 137行 httpd-ahssl.conf

    C:\Users\Administrator>E:\PHP\Apache24\bin\httpd.exe -w -n "apache2.4" -k startAH00526: ...

  9. 未能读取并闩锁页 (1:xxxxx)(用闩锁类型 SH)

    设置数据库为紧急模式 停掉SQL Server服务: 把应用数据库的数据文件XXX_Data.mdf移走: 重新建立一个同名的数据库XXX: 停掉SQL服务: 把原来的数据文件再覆盖回来: 运行以下语 ...

  10. 【Android】获取手机中已安装apk文件信息(PackageInfo、ResolveInfo)(应用图片、应用名、包名等)

    众所周知,通过PackageManager可以获取手机端已安装的apk文件的信息,具体代码如下 PackageManager packageManager = this.getPackageManag ...