kuangbin专题 专题一 简单搜索 Oil Deposits HDU - 1241
题目链接:https://vjudge.net/problem/HDU-1241
题意:问有几个油田,一个油田由相邻的‘@’,组成。
思路:bfs,dfs都可以,只需要遍历地图,遇到‘@’,跑一遍搜索,标记跑过的点,然后油田数+1.
#include <iostream>
#include <cstring>
#include<vector>
#include<string>
#include <cmath>
#include <map>
#include <queue>
#include <algorithm>
using namespace std; #define inf (1LL << 31) - 1
#define rep(i,j,k) for(int i = (j); i <= (k); i++)
#define rep__(i,j,k) for(int i = (j); i < (k); i++)
#define per(i,j,k) for(int i = (j); i >= (k); i--)
#define per__(i,j,k) for(int i = (j); i > (k); i--) const int N = ;
int mv[][] = { { , }, { , - }, { , }, { -, },
{ , }, { -, - }, { -, }, { , - } };
char mp[N][N];
bool vis[N][N];
int n, m; struct node{
int x, y;
}; inline void init(){
rep(i, , n) rep(j, , m) vis[i][j] = false;
} inline void input(){ init();
rep(i, , n) rep(j, , m) cin >> mp[i][j];
} inline bool check(int x, int y){
return x >= && x <= n && y >= && y <= m;
} void bfs(int now_x, int now_y){ vis[now_x][now_y] = true; queue<node> que;
que.push(node{ now_x, now_y }); while (!que.empty()){ node tmp = que.front();
que.pop(); rep__(p, , ){
int dx = tmp.x + mv[p][];
int dy = tmp.y + mv[p][]; if (check(dx, dy) && !vis[dx][dy] && mp[dx][dy] == '@'){
vis[dx][dy] = true;
que.push(node{ dx, dy });
}
}
}
} void work(){ int ans = ; rep(i, , n) rep(j, , m){
//附加条件,这个‘@’没被访问过,说明是新的油田的一部分
if (mp[i][j] == '@' && !vis[i][j]){
bfs(i, j);
++ans;
}
} cout << ans << endl;
} int main(){ ios::sync_with_stdio(false);
cin.tie(); while (cin >> n >> m){ if (m == ) break; input();
work();
} return ;
}
kuangbin专题 专题一 简单搜索 Oil Deposits HDU - 1241的更多相关文章
- Oil Deposits HDU - 1241 (dfs)
Oil Deposits HDU - 1241 The GeoSurvComp geologic survey company is responsible for detecting undergr ...
- (深搜)Oil Deposits -- hdu -- 1241
链接: http://acm.hdu.edu.cn/showproblem.php?pid=1241 Time Limit: 2000/1000 MS (Java/Others) Memory ...
- Oil Deposits HDU 1241
The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSu ...
- kuangbin专题总结一 简单搜索
A - 棋盘问题:在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别.要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子的所有 ...
- 搜索入门_简单搜索bfs dfs大杂烩
dfs题大杂烩 棋盘问题 POJ - 1321 和经典的八皇后问题一样. 给你一个棋盘,只有#区域可以放棋子,同时同一行和同一列只能有一个棋子. 问你放k个棋子有多少种方案. 很明显,这是搜索题. ...
- [kuangbin带你飞]专题一 简单搜索
ID Origin Title 454 / 1008 Problem A POJ 1321 棋盘问题 328 / 854 Problem B POJ 2251 Dungeon Ma ...
- 搜索专题:HDU1241 Oil Deposits
Oil Deposits Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tot ...
- hdu 1241 Oil Deposits (简单搜索)
题目: The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. ...
- HDU 1241 Oil Deposits DFS(深度优先搜索) 和 BFS(广度优先搜索)
Oil Deposits Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...
随机推荐
- jquery 可以给事件传参数
<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...
- 【全面解禁!真正的Expression Blend实战开发技巧】第十章 FluidMoveBehavior完全解析之三飞出ListBox吧
原文:[全面解禁!真正的Expression Blend实战开发技巧]第十章 FluidMoveBehavior完全解析之三飞出ListBox吧 刚才有人说我的标题很给力,哈哈.那这个标题肯定更给力了 ...
- TThreadList Demo
type TForm1 = class(TForm) Button1: TButton; Button3: TButton; ListBox1: TListBox; Button2: TButton; ...
- SQL Server修改标识列方法(备忘)
原文:SQL Server修改标识列方法(备忘) SQL Server修改标识列方法 ----允许对系统表进行更新 exec sp_configure 'allow updates',1 reconf ...
- Win10《芒果TV》商店版更新v3.2.3:新增应用内意见反馈、播放重试、透明磁贴
在2016圣诞节临近之际,<芒果TV>UWP版迅速更新v3.2.3版,主要是新增应用内意见反馈提交功能.播放重试.透明磁贴.动态磁贴等功能,进一步优化稳定性.视觉细节.运行速度. 芒果TV ...
- CPU和GPU双低效,摩尔定律之后一万倍 ——写于TPU版AlphaGo重出江湖之际
本文来自计算机体系结构专家王逵.他认为,“摩尔定律结束之后,性能提升一万倍”不会是科幻,而是发生在我们眼前的事实. 2008年,<三体2:黑暗森林>里写到: 真的很难,你冬眠后不久 ...
- UWP的TextBox和PasswordBox使用输入范围更改触摸键盘InputScope
原文:UWP的TextBox和PasswordBox使用输入范围更改触摸键盘InputScope 当你的应用运行在具有触摸屏的设备上时,触摸键盘可用于文本输入.当用户点击可编辑的输入字段(如 Text ...
- UWP SQLite的使用
原文:UWP SQLite的使用 1.准备工作 1.首先我们要给项目添加"SQLite for Universal Windows Platform"扩展 点击菜单栏的" ...
- 《HTML开发Mac OS App 视频教程》 第001讲、入门教程
土豆网同步更新:http://www.tudou.com/plcover/VHNh6ZopQ4E/ 使用HTML 创建Mac OS App 视频教程. 官方QQ群: (1)App实践出真知 434 ...
- C++大小写转换和性能(C语言,C++,API,STL一共4种方法)
大小写转换和性能 前言 本文主要讨论最基本的一些大小写转换函数和API,不讨论一些常见的字符串程序库里面的大小写转换接口,另外本文的落脚点是这些转换函数的性能和日常开发中遇到的一些问题. 不考虑范围 ...