L - Oil Deposits HDU - 1241
L - Oil Deposits HDU - 1241
注意写check的时候要先判x,y是不是越界了,不然直接用数组可能RE, 也可能直接WA了
#include<cstdio>
#include<iostream>
#include<cstring>
const int maxn = 110;
using namespace std;
int m, n;
char mp[maxn][maxn];
bool vis[maxn][maxn];
int dx[] = {0,0,1,-1,1,1,-1,-1};
int dy[] = {1,-1,0,0,-1,1,1,-1};bool check(int x, int y) {if(x < 1 || x > m || y > n || y < 1) return 0;if(vis[x][y] || mp[x][y] == '*') return 0;return 1;
}void dfs(int x, int y) {vis[x][y] = 1;for(int i = 0; i < 8; i++) {int nx = x + dx[i], ny = y + dy[i];if(check(nx, ny)) {vis[nx][ny] = 1;dfs(nx, ny);}}
}int main() {// freopen("test.in", "r", stdin);while(scanf("%d", &m) && m) {int ans = 0;scanf("%d", &n);memset(vis, 0, sizeof(vis));for(int i = 1; i <= m; i++) cin >> mp[i] + 1;for(int i = 1; i <= m; i++) {for(int j = 1; j <= n; j++) {if(mp[i][j] == '@' && !vis[i][j]) dfs(i, j), ans++;}}printf("%d\n", ans);}return 0;
}
L - Oil Deposits HDU - 1241相关推荐
- Oil Deposits HDU - 1241 并查集思想 + bfs搜索
题目 在第一次植物僵尸世界大战中,植物国的黑玫瑰王子使用了植物国的超超超超级无敌禁术-----"BUG",开启了异次元的大门,在一位超超超超-级的指挥官"辅助器" ...
- L - Oil Deposits
题目描述 The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. ...
- 【HDU - 1241】Oil Deposits (连通块问题 属于求大海中的岛屿个数 类似问题)
题干: The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. G ...
- UVa572 Oil Deposits DFS求连通块
技巧:遍历8个方向 for(int dr = -1; dr <= 1; dr++)for(int dc = -1; dc <= 1; dc++)if(dr != 0 || dc != 0) ...
- HDU-1241 Oil Deposits (DFS)
Oil Deposits Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total ...
- 【POJ - 1562】Oil Deposits (dfs搜索,连通块问题)
题干: The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. G ...
- NUC1397 Oil Deposits【DFS】
Oil Deposits 时间限制: 1000ms 内存限制: 65535KB 问题描述 The GeoSurvComp geologic survey company is responsible ...
- 百-寒-进-16-油田Oil Deposits
Oil Deposits 题目描述 GeoSurvComp地质调查公司负择探测地下石油矿床.该公司一次处理一个大的矩形区域,并创建一个网格,将土地划分为许多正方形地块.然后,它分别分析每个地块,使用传 ...
- hdu 1241 Oil Deposits 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1241 第一次写搜索代码 花了好大的功夫检查 看了别人的结题报告 还是错误一大堆 哎 题目是这样的 @表 ...
最新文章
- redis 主从复制功能 原理
- linux查看mongo表大小,MongoDB_mongodb 查看数据库和表大小,1,查看数据库db.stats() - phpStudy...
- SQLSERVER常用函数汇总
- java实现系统多级文件夹复制
- 网络协议——TCP/IP协议
- iOS开发:iPhone6、6 plus适配
- 【收藏】linux下用命令方式创建及管理kvm虚拟机
- 优化你的手游:使用脏矩形技术
- linux 用mutex定义一个linkedlist,【基于LINUX的操作系统实验教程最终版材料】
- MUI 里js动态添加数字输入框后,增加、减少按钮无效
- matlab时频分析工具箱安装_科研小班 | 加州大学伯克利分校 | 物理、电子工程:MATLAB信号和数据处理课题...
- php打印倒立金字塔,编写程序打印*字符形成的等腰三角形倒立金字塔图形 ******* ***** *** *...
- 当心币圈高仿号!也别指望AI,它有心无力
- java调用Dos命令
- entOS查看系统信息-CentOS查看命令
- 基于Python的心电信号检测与处理
- jq22插件库视频播放插件Video.js,jq22资源分享
- 光机电气一体化控制实训系统
- 【SMAP 土壤水分的质量处理】
- oracle11G修改数据库默认端口