(简单) POJ 1562 Oil Deposits,BFS。
Description
#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。的更多相关文章
- POJ 1562 Oil Deposits (并查集 OR DFS求联通块)
Oil Deposits Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 14628 Accepted: 7972 Des ...
- [POJ] 1562 Oil Deposits (DFS)
Oil Deposits Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 16655 Accepted: 8917 Des ...
- HDU - 1241 POJ - 1562 Oil Deposits DFS FloodFill漫水填充法求连通块问题
Oil Deposits The GeoSurvComp geologic survey company is responsible for detecting underground oil de ...
- poj 1562 Oil Deposits (广搜,简单)
题目 简单的题目,只是测试案例的输入后面可能有空格,所以要注意一下输入方式. #define _CRT_SECURE_NO_WARNINGS //题目的案例输入n,m后面有些貌似有空格... #inc ...
- POJ 1562 Oil Deposits (HDU 1241 ZOJ 1562) DFS
现在,又可以和她没心没肺的开着玩笑,感觉真好. 思念,是一种后知后觉的痛. 她说,今后做好朋友吧,说这句话的时候都没感觉.. 我想我该恨我自己,肆无忌惮的把她带进我的梦,当成了梦的主角. 梦醒之后总是 ...
- POJ 1562 Oil Deposits
转载请注明出处:http://blog.csdn.net/a1dark 大规模的图论切题之旅正式开始了.由于今天停了一天的电.所以晚上才开始切题.直到昨晚才把图论大概看了一遍.虽然网络流部分还是不怎么 ...
- HDU 1562 Oil Deposits
题目: The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. G ...
- (简单) POJ 3414 Pots,BFS+记录路径。
Description You are given two pots, having the volume of A and B liters respectively. The following ...
- HDU 1241 - Oil Deposits - [BFS]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1241 题意: 求某块平面上,连通块的数量.一个油田格子若周围八个方向也有一个油田格子,则认为两者相连通 ...
随机推荐
- linux 查看 cpu 和内存的命令 - top
1.查看内存,cpu ,当前进程task数目, 每个进程的cpu, 内存使用率, 用top 命令: 在这个页面,按 P,下面的进程排序,以cpu使用率降序排列. 按M,按内存使用率降序排列: 按N, ...
- Android根据Button状态(normal,focused,pressed)显示不同背景图片
Android根据Button状态(normal,focused,pressed)显示不同背景图片 Android中Button 有focused, selected, pressed 等不同状态,通 ...
- JS-DOM元素灵活查找
用className选择元素 封装成函数 <title>无标题文档</title> <script> /* window.onload=function () { ...
- HDU1969:Pie(二分)
Pie Time Limit : 5000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Submissio ...
- Mesos架构
Mesos Architecture 上图显示了 Mesos 的主要组成部分. Mesos 由一个 master daemon 来管理 slave daemon 在每个集群节点上的运行, mesos ...
- Light OJ - 1058 Parallelogram Counting(判定平行四边形)
Description There are n distinct points in the plane, given by their integer coordinates. Find the n ...
- 转:lr_eval_string函数的用法解析
在LR中,C的变量和LR的参数是不一样的. 任何C的变量都不能被LR的函数直接调用. 应该用lr_eval_string来取值. 比如{NewParam}(LR中参数化的变量)直接用这个引用是没有问题 ...
- EF5修改edmx表结构保存后不自动更新tt (转)
http://blog.csdn.net/panderman/article/details/8172968 不知道这算不算一个bug,当你新建一个从数据库生成的edmx时,他能正确的生成所有的tt文 ...
- git bash退回上一个文件夹
cd ..\ a@w3311 MINGW32 /f/Projects/crm (master) $ cd..\ > bash: cd..: command not found a@w3311 M ...
- Base64笔记
1. 昨天的<MIME笔记>中提到,MIME主要使用两种编码转换方式----Quoted-printable和Base64----将8位的非英语字符转化为7位的ASCII字符. 虽然这样的 ...