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. HDU 5234 Happy birthday 动态规划(三维数组)

    题目大意:过生日,有一个N*M的表格,每个位置都有一块一定重量的蛋糕你可以选择吃完或者不吃,从(1,1)走到(n,m),每次只能向右走或向下走,最多能吃k重量的蛋糕.问你最多能吃多少蛋糕. 题目思路: ...

  2. Swift の 函数式编程

    Swift 相比原先的 Objective-C 最重要的优点之一,就是对函数式编程提供了更好的支持. Swift 提供了更多的语法糖和一些新特性来增强函数式编程的能力,本文就在这方面进行一些讨论. S ...

  3. 关键自li,em,dl,ul,ol,footer,header,nav,aside,article

    section 版块 用于划分页面上的不同区域,或者划分文章里不同的节 header 页面头部或者版块(section)头部 footer 页面底部或者(section)底部 nav 导航 (包含链接 ...

  4. 初探JavaScript魅力(五)

    JS简易日历    innerHTML <title>无标题文档</title> <script> var neirong=['一','二','三','四','五' ...

  5. Basically Speaking

    Basically Speaking Time Limit: 2 Sec  Memory Limit: 200 MB Submit: 19  Solved: 11 [Submit][Status][W ...

  6. SEO优化之 主页上加上nofollow

    <a href=http://www.主页.cn/ rel=”nofollow”>这里是锚文字</a> <光年日志分析系统>来分析抓取比较多的是哪个网页,没用的no ...

  7. mysql导出表结构

    在命令行下mysql的数据导出有个很好用命令mysqldump,它的参数有一大把,可以这样查看: mysqldump 最常用的: mysqldump -uroot -pmysql databasefo ...

  8. di

    dependency inversion依赖反转和dependency inversion依赖注入 di反转指的是不依赖于具体的实现而是依赖于抽象的接口,那么运行应用的main方法里如果创造具体实现的 ...

  9. git:解决The current branch is not configured for pull No value for key branch.master.merge found in config

    网上多半都是命令行下的解决方案,我用的是EGit,所以要在eclipse里(我的版本是kepler)把下面这句话添加到配置文件中. Window->Preference->Team-> ...

  10. 转 ORACLE数据库它可以存储 中文 字节或字符

    一:因为ORACLE数据库它可以存储字节或字符,例如 CHAR(12 BYTE) CHAR(12 CHAR)的意义是不同的.一般来说默认是存储字节,你可以查看数据库参数NLS_LENGTH_SEMAN ...