这道题明明很简单但不知道为什么运行结果一直错,但提交却是对的!代码真是神奇,不过我猜测可能是提上给出的数据错了,可能提上给的数据m和n后多给了一个空格或回车,但题的数据没有

  1. #include<stdio.h>
  2. #include<string.h>
  3. #define N 110
  4. int m, n;
  5. char maps[N][N];
  6. int dir[8][2]={{-1, -1}, {-1, 0}, {-1, 1}, {0, -1}, {0, 1}, {1, -1}, {1, 0}, {1, 1}};
  7.  
  8. void DFS(int x, int y);
  9.  
  10. int main()
  11. {
  12. while(scanf("%d%d", &m, &n), m!=0)
  13. {
  14. int ans=0;
  15. for(int i=0; i<m; i++)
  16. {
  17. getchar();
  18. for(int j=0; j<n; j++)
  19. {
  20. scanf("%c", &maps[i][j]);
  21. }
  22. }
  23.  
  24. for(int i=0; i<m; i++)
  25. for(int j=0; j<n; j++)
  26. {
  27. if(maps[i][j]=='@')
  28. {
  29. DFS(i, j);
  30. ans++;
  31. }
  32. }
  33.  
  34. printf("%d\n", ans);
  35. }
  36. }
  37.  
  38. void DFS(int x, int y)
  39. {
  40. maps[x][y]='*';
  41. for(int i=0; i<8; i++)
  42. {
  43. int nx=x+dir[i][0];
  44. int ny=y+dir[i][1];
  45.  
  46. if(maps[nx][ny]=='@'&&nx>=0&&nx<m&&ny>=0&&ny<n)
  47. DFS(nx, ny);
  48.  
  49. }
  50. }

  

HDU 1241 油田的更多相关文章

  1. HDU 1241 Oil Deposits --- 入门DFS

    HDU 1241 题目大意:给定一块油田,求其连通块的数目.上下左右斜对角相邻的@属于同一个连通块. 解题思路:对每一个@进行dfs遍历并标记访问状态,一次dfs可以访问一个连通块,最后统计数量. / ...

  2. HDOJ(HDU).1241 Oil Deposits(DFS)

    HDOJ(HDU).1241 Oil Deposits(DFS) [从零开始DFS(5)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架 ...

  3. DFS(连通块) HDU 1241 Oil Deposits

    题目传送门 /* DFS:油田问题,一道经典的DFS求连通块.当初的难题,现在看上去不过如此啊 */ /************************************************ ...

  4. hdu 1241 Oil Deposits(DFS求连通块)

    HDU 1241  Oil Deposits L -DFS Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & ...

  5. 深搜基础题目 杭电 HDU 1241

    HDU 1241 是深搜算法的入门题目,递归实现. 原题目传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1241 代码仅供参考,c++实现: #incl ...

  6. HDU 1241 Oil Deposits(石油储藏)

    HDU 1241 Oil Deposits(石油储藏) 00 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)   Probl ...

  7. Oil Deposits HDU - 1241 (dfs)

    Oil Deposits HDU - 1241 The GeoSurvComp geologic survey company is responsible for detecting undergr ...

  8. HDU 1241 - Oil Deposits - [BFS]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1241 题意: 求某块平面上,连通块的数量.一个油田格子若周围八个方向也有一个油田格子,则认为两者相连通 ...

  9. HDU 1241 (DFS搜索+染色)

    题目链接:  http://acm.hdu.edu.cn/showproblem.php?pid=1241 题目大意:求一张地图里的连通块.注意可以斜着连通. 解题思路: 八个方向dfs一遍,一边df ...

随机推荐

  1. python 之 赋值和拷贝(你真的了解吗)

    现象:先上一段代码. >>> import copy >>> a = [1,2,3,4,['a','b']] >>> b = a >> ...

  2. iOS 将金钱变为逗号形式

    ; NSNumberFormatter * formatter = [NSNumberFormatter new]; [formatter setNumberStyle:NSNumberFormatt ...

  3. Html5-Canvas 与 SVG 的比较

    Canvas 与 SVG 的比较 Canvas 依赖分辨率 不支持事件处理器 弱的文本渲染能力 能够以 .png 或 .jpg 格式保存结果图像 最适合图像密集型的游戏,其中的许多对象会被频繁重绘 S ...

  4. 【IDEA】单元测试:项目中引入JUnit测试框架+Mock简单了解

    一.Junit 使用和说明: 参考:单元测试第三弹--使用JUnit进行单元测试-HollisChuang's Blog http://www.hollischuang.com/archives/17 ...

  5. 怎样sublime显示文件夹

    1.Project -> Add Folder to Project 2.选择你要添加的文件文件 效果图

  6. delphi -----获取计算IP

    function GetHostName:String; var ComputerName: ..MAX_COMPUTERNAME_LENGTH+] of char; Size: Cardinal; ...

  7. delphi xe----操作mongoDB驱动,TMongoWire(Delphi MongoDB Driver)

    所有例子来自:https://github.com/stijnsanders/TMongoWire Delphi MongoDB的驱动 一个Delphi的驱动程序来访问mongoDB的服务器.用jso ...

  8. sublime使用及插件

    转自 http://www.cnblogs.com/Rising/p/3741116.html

  9. 剑指Offer——重建二叉树

    题目描述: 输入某二叉树的前序遍历和中序遍历的结果,请重建出该二叉树.假设输入的前序遍历和中序遍历的结果中都不含重复的数字.例如输入前序遍历序列{1,2,4,7,3,5,6,8}和中序遍历序列{4,7 ...

  10. reload函数

    reload函数 python2中reload()是内置函数,可以直接调用: reload() python3中将reload()函数放到了imp包中,需要先引入imp包: from imp impo ...