HDU 1241 油田
这道题明明很简单但不知道为什么运行结果一直错,但提交却是对的!代码真是神奇,不过我猜测可能是提上给出的数据错了,可能提上给的数据m和n后多给了一个空格或回车,但题的数据没有
#include<stdio.h>
#include<string.h>
#define N 110
int m, n;
char maps[N][N];
int dir[8][2]={{-1, -1}, {-1, 0}, {-1, 1}, {0, -1}, {0, 1}, {1, -1}, {1, 0}, {1, 1}}; void DFS(int x, int y); int main()
{
while(scanf("%d%d", &m, &n), m!=0)
{
int ans=0;
for(int i=0; i<m; i++)
{
getchar();
for(int j=0; j<n; j++)
{
scanf("%c", &maps[i][j]);
}
} for(int i=0; i<m; i++)
for(int j=0; j<n; j++)
{
if(maps[i][j]=='@')
{
DFS(i, j);
ans++;
}
} printf("%d\n", ans);
}
} void DFS(int x, int y)
{
maps[x][y]='*';
for(int i=0; i<8; i++)
{
int nx=x+dir[i][0];
int ny=y+dir[i][1]; if(maps[nx][ny]=='@'&&nx>=0&&nx<m&&ny>=0&&ny<n)
DFS(nx, ny); }
}
HDU 1241 油田的更多相关文章
- HDU 1241 Oil Deposits --- 入门DFS
HDU 1241 题目大意:给定一块油田,求其连通块的数目.上下左右斜对角相邻的@属于同一个连通块. 解题思路:对每一个@进行dfs遍历并标记访问状态,一次dfs可以访问一个连通块,最后统计数量. / ...
- HDOJ(HDU).1241 Oil Deposits(DFS)
HDOJ(HDU).1241 Oil Deposits(DFS) [从零开始DFS(5)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架 ...
- DFS(连通块) HDU 1241 Oil Deposits
题目传送门 /* DFS:油田问题,一道经典的DFS求连通块.当初的难题,现在看上去不过如此啊 */ /************************************************ ...
- hdu 1241 Oil Deposits(DFS求连通块)
HDU 1241 Oil Deposits L -DFS Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & ...
- 深搜基础题目 杭电 HDU 1241
HDU 1241 是深搜算法的入门题目,递归实现. 原题目传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1241 代码仅供参考,c++实现: #incl ...
- HDU 1241 Oil Deposits(石油储藏)
HDU 1241 Oil Deposits(石油储藏) 00 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Probl ...
- Oil Deposits HDU - 1241 (dfs)
Oil Deposits HDU - 1241 The GeoSurvComp geologic survey company is responsible for detecting undergr ...
- HDU 1241 - Oil Deposits - [BFS]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1241 题意: 求某块平面上,连通块的数量.一个油田格子若周围八个方向也有一个油田格子,则认为两者相连通 ...
- HDU 1241 (DFS搜索+染色)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1241 题目大意:求一张地图里的连通块.注意可以斜着连通. 解题思路: 八个方向dfs一遍,一边df ...
随机推荐
- AderTemplate
http://www.cnblogs.com/kwklover/archive/2007/07/12/815509.html 概述 AderTemplate是一个小型的模板引擎.无论是拿来直接使用还是 ...
- Cocos2d-x 3.3Bate0 ExpandedListView
之前写的ExpandedListView版本号因为版本号升级这里提供Cocos2d-x 3.3Bate0 版本号 代码下载:http://download.csdn.net/detail/qqmcy/ ...
- @RequestMapping 注解
@RequestMapping 注解开发者需要在控制器内部为每一个请求动作开发相应的处理方法.org.springframework.web.bind.annotation.RequestMappin ...
- cascade(级联)和inverse关系详解
序言 写这篇文章之前,自己也查了很多的资料来搞清楚这两者的关系和各自所做的事情,但是百度一搜,大多数博文感觉说的云里雾里,可能博主自己清楚是怎么一回事,但是给一个不懂的人或者一知半解的人看的话,别人也 ...
- 【BZOJ1367】[Baltic2004]sequence 左偏树
[BZOJ1367][Baltic2004]sequence Description Input Output 一个整数R Sample Input 7 9 4 8 20 14 15 18 Sampl ...
- 云计算之路:2009年Xen一个补丁背后那不为人知的故事
仔细阅读了http://www.cnblogs.com/cmt/p/3729386.html这篇关于xen的博文,这篇博文写的挺赞的,分析的也很细致,涉及到4年前的一个patch的故事.在讲这个故事之 ...
- ETCD数据空间压缩清理
场景:做etcd数据镜像的时候出现如下错误 Error: etcdserver: mvcc: database space exceeded 通过查找官方文档https://coreos.com/e ...
- Windows File 管理工具:junction And Subinacl
junction.exe 是 Sysinternals 出品的命令行工具.使用前建议将其复制到%SystemRoot%/system32目录下 创建一个名为 D:/LINK 的[junction ...
- Windows Server 2008及以上系统磁盘无法查看(About UAC and ACE)
在windows Server2008及以上系統,如果UAC Enabled,ACE列表中不會包含Administrators成員的SID,所以即使你是administrators的成員,也無法訪問D ...
- Struts 上传文件
1. 客户端注意事项 method="post" enctype="multipart/form-data" <input type="file ...