hdu 1241(DFS/BFS)
Oil Deposits
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 38801 Accepted Submission(s): 22518
1 1
*
3 5
*@*@*
**@**
*@*@*
1 8
@@****@*
5 5
****@
*@@*@
*@**@
@@@*@
@@**@
0 0
Sample Output
0
1
2
2
Statistic | Submit | Discuss | Note
思路:'@'代表有石油,然后只要上下相邻或者左右相邻,或者对角相邻都算是一块石油,问有几块石油储备。
就是用dfs或者bfs就行了,得用栈或者队列来模拟。我写的是DFS版
不知道为什么在用scanf读入字符数组时,题目的第四组测试数据总是读入回车。。。getchar也不管用。
换cin好了。。。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <conio.h> using namespace std; typedef struct info{
int i,j;
}location; int m,n;
int countt;
char t;
char oilmap[][];
stack<location> s; int calx[]={-,-,-,,,,,};
int caly[]={-,,,-,,-,,}; void exploit(int i,int j){
location temp={i,j};
location now,next;
s.push(temp);
while(!s.empty()){
now=s.top();
s.pop();
oilmap[now.i][now.j]='*';
for(int k=;k<;k++){
next.i=now.i+calx[k];
next.j=now.j+caly[k];
if(next.i>= && next.i<m && next.j>= && next.j<n){
if(oilmap[next.i][next.j]=='@'){
s.push(next);
}
}
}
} } int main()
{
while(~scanf("%d %d",&m,&n)){
getchar();
if(m==) {break;}
for(int i=;i<m;i++){
for(int j=;j<n;j++){
cin>>oilmap[i][j];
}
}
countt=;
for(int i=;i<m;i++){
for(int j=;j<n;j++){
if(oilmap[i][j]=='@'){
exploit(i,j);
countt++;
}
}
}
printf("%d\n",countt);
}
return ;
}
hdu 1241(DFS/BFS)的更多相关文章
- Oil Deposits HDU - 1241 (dfs)
Oil Deposits HDU - 1241 The GeoSurvComp geologic survey company is responsible for detecting undergr ...
- HDU 4771 (DFS+BFS)
Problem Description Harry Potter has some precious. For example, his invisible robe, his wand and hi ...
- HDU - 1241 dfs or bfs [kuangbin带你飞]专题一
8个方向求联通块,经典问题. AC代码 #include<cstdio> #include<cstring> #include<algorithm> #includ ...
- HDU 1241 (DFS搜索+染色)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1241 题目大意:求一张地图里的连通块.注意可以斜着连通. 解题思路: 八个方向dfs一遍,一边df ...
- hdu 1242 dfs/bfs
Problem Description Angel was caught by the MOLIGPY! He was put in prison by Moligpy. The prison is ...
- HDU 1241 DFS
Oil Deposits Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tota ...
- HDU 1241 Oil Deposits --- 入门DFS
HDU 1241 题目大意:给定一块油田,求其连通块的数目.上下左右斜对角相邻的@属于同一个连通块. 解题思路:对每一个@进行dfs遍历并标记访问状态,一次dfs可以访问一个连通块,最后统计数量. / ...
- hdu 1241 Oil Deposits(DFS求连通块)
HDU 1241 Oil Deposits L -DFS Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & ...
- HDOJ(HDU).1241 Oil Deposits(DFS)
HDOJ(HDU).1241 Oil Deposits(DFS) [从零开始DFS(5)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架 ...
随机推荐
- pygame-KidsCanCode系列jumpy-part15-PowerUp加速器
这一节我们给游戏增加点额外的奖励,大多数游戏中都会有金币.装备啥的来激励玩家,在jumpy这个游戏中,我们也可以增加类似的道具:加速器.效果图如下: 档板上会随机出现一些加速器(power up),小 ...
- jQuery鼠标悬停3d菜单展开动画
效果体验:http://hovertree.com/texiao/jquery/93/ 竖直的主菜单贴着页面左侧,当光标移入菜单项时,以3D动画的方式弹出对应的二级菜单.采用jQuery和CSS3实现 ...
- APP中的图片如何长按可以下载并保存图片到相册出错处理
https://www.cnblogs.com/interdrp/p/9302164.html 接上文. 如果用户在保存图片过程中,不小心拒绝了相册的访问权限
- Cocos Creator下删除AnySDK步骤
1.删除 frameworks/runtime-src/Classes 下的 jsb_anysdk_basic_conversions.cpp manualanysdkbindings.cpp jsb ...
- Maven中classifier
1.classifier概述 classifier通常用于区分从同一POM构建的具有不同内容的构件(artifact).它是可选的,它可以是任意的字符串,附加在版本号之后. 2.使用场景 场景一:区分 ...
- GPG(GnuPG)入门
GPG(GnuPG)入门 下载: https://gnupg.org/download/index.html 或者 http://www.hellopp.cn/page/5b9a1405c3f1f7d ...
- jsp执行过程图解
转自:https://blog.csdn.net/y277an/article/details/76561451 一.jsp执行过程图解 用户访问jsp页面时,jsp的处理过程如下图所示: 二.预处理 ...
- htop使用详解
一.Htop的使用简介 大家可能对top监控软件比较熟悉,今天我为大家介绍另外一个监控软件Htop,姑且称之为top的增强版,相比top其有着很多自身的优势.如下: 两者相比起来,top比较繁琐 默认 ...
- win7&win10 右键添加 cmd
修改注册表,位置有 3 个,重复即可: 桌面右键: HKEY_CLASSES_ROOT\Directory\Background\shell 文件夹右键:HKEY_CLASSES_ROOT\Direc ...
- 在Ubuntu18.04下配置HBase
HBase在HDFS基础上提供了高可靠, 列存储, 可扩展的数据库系统. HBase仅能通过主键(row key)和主键的range来检索数据, 主要用来存储非结构化和半结构化的松散数据. 与Hado ...