poj 1562 Oil Deposits (广搜,简单)
简单的题目,只是测试案例的输入后面可能有空格,所以要注意一下输入方式。
#define _CRT_SECURE_NO_WARNINGS
//题目的案例输入n,m后面有些貌似有空格。。。
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
using namespace std;
#define MAXN 110
//bool vis[MAXN][MAXN];
char map[MAXN][MAXN];
int n,m,sum;
int xx[]={,,,,,-,-,-};
int yy[]={,-,,,-,,,-};
struct tt
{
int x,y;
}; int bfs()
{
int ans=;
tt front,rear,temp;
queue<tt>q;
while(!q.empty())
q.pop();
// memset(vis,false,sizeof(vis));
for(int j=;j<n;j++)
{
for(int k=;k<m;k++)
{
if(map[j][k]=='@')
{
ans++;
sum--;
map[j][k]='*';
if(sum==)return ans;
front.x=j,front.y=k;
q.push(front);
while(!q.empty())
{
temp=q.front();
q.pop();
for(int i=;i<;i++)
{
rear.x=temp.x+xx[i];
rear.y=temp.y+yy[i];
if(rear.x>=&&rear.x<n&&rear.y>=&&rear.y<m&&map[rear.x][rear.y]=='@')
{
map[rear.x][rear.y]='*';
q.push(rear);
sum--;
if(sum==)return ans;
}
}
}
}
}
}
return ans;
} int main()
{
int i,j;
while(scanf("%d%d",&n,&m)!=EOF)
{
if(n==&&m==)
break;
sum=;
for(i=;i<n;i++)
{
scanf("%s",map[i]);//因为输入后貌似有时有空格,所以这么输入好了
for(j=;j<m;j++)
{
if(map[i][j]=='@')
sum++;
} }
printf("%d\n",bfs());
}
return ;
}
poj 1562 Oil Deposits (广搜,简单)的更多相关文章
- (简单) POJ 1562 Oil Deposits,BFS。
Description The GeoSurvComp geologic survey company is responsible for detecting underground oil dep ...
- 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 (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 ...
- poj1562 Oil Deposits 深搜模板题
题目描述: Description The GeoSurvComp geologic survey company is responsible for detecting underground o ...
- poj 3414 Pots(广搜BFS+路径输出)
转载请注明出处:http://blog.csdn.net/u012860063?viewmode=contents 题目链接:id=3414">http://poj.org/probl ...
随机推荐
- ZigBee协议基本介绍
ZigBee是一种短距离(10~100米).低速率(20~250Kbps).底成本.低功耗的无线网络技术,主要用于近离无线通讯.能够做到在数千个微小的传感器之间相互协调实现通讯,这些传感器只需要很少的 ...
- Windows Phone 7 中拷贝文件到独立存储
private void CopyToIsolatedStorage(){ using (IsolatedStorageFile storage = IsolatedStorageFile.Ge ...
- 添加远程链接MySQL的权限
mysql> grant 权限1,权限2,…权限n on 数据库名称.表名称 to 用户名@用户地址 identified by ‘连接口令’; 权限1,权限2,…权限n代表select,ins ...
- 文件墙 CFilewall
文件墙 CFilewall 记于 2013-09-26 == @[代码] [C#] []WPF] #### 使用了一些公司的组件和放大,但是不多,可以单独抽取出来 --- 程序结构 - Control ...
- Android砖机救活(索爱MT15i)
前言 接触Android时间长了就想编译一套属于自己的系统,摘取不必要的那些组件,然后刷到手机上,俗话说的好,“常在河 边走,哪有不湿鞋”.果不其然,刷完自己编译的系统手机变砖了,具体情况为 开不开机 ...
- RHEL安装docker-compose
Note that Compose 1.5.2 requires Docker 1.7.1 or later. pip install docker-compose==1.5.2 Note that ...
- delphi下,不错的多语言翻译组件
http://yktoo.com/en/software/dklangTraned http://sourceforge.net/projects/dklang/
- Linq to Entities
首先要添加一个ADO.NET实体数据模型 添加一个Entities 对象,其用法和linqtosql类似例如: StudentInfoEntities2 entity = new StudentInf ...
- android连接本地tomcat服务器,报timeout
1.在eclipse环境下连接时,没有任何问题 2.直接将服务端发布到tomcat服务下,报timeout 3.查明原因: 3.1打开IE访问,一切正常,可以获取到数据,说明不是服务端的问题 3.2打 ...
- CentOS 7.0安装MPlayer
自带的播放器不管rmvb还是mp4都不能播放,也搜索不到解码器. CentOS7epel装不上所以也没有rpmfusion,所以决定自己编译mplayer 首先是要获取源代码. 首先是主程序的源代码. ...