hdu 1204 深搜

  1. #include <iostream>
  2. #include <string>
  3. #define MAX 110
  4. #define OIL true
  5. #define BLANK false
  6. using namespace std;
  7. bool oil_map[MAX][MAX];
  8. int dir_map[8][2]={ {1,0},{-1,0},{0,1},{0,-1},{1,1},{1,-1},{-1,1},{-1,-1} };
  9. void set_oil_map()
  10. {
  11. memset(oil_map,BLANK,sizeof(oil_map) );
  12. }
  13. void input_oil_map(int x,int y)
  14. {
  15. for(int i=1 ;i<=x ;i++)
  16. {
  17. string temp;
  18. cin>>temp;
  19. for(int j=1 ;j<=y ;j++)
  20. {
  21. if(temp[j-1]==‘@‘ )
  22. oil_map[i][j]=OIL;
  23. }
  24. }
  25. }
  26. void search_oil_map(int x ,int y)
  27. {
  28. //if(oil_map[x][y]==OIL )
  29. oil_map[x][y]=BLANK;
  30. int search_x,search_y;
  31. for(int i=0 ;i<8 ;i++)
  32. {
  33. search_x=x+dir_map[i][0];
  34. search_y=y+dir_map[i][1];
  35. if(oil_map[search_x][search_y]==OIL )
  36. search_oil_map(search_x ,search_y );
  37. }
  38. }
  39. int main()
  40. {
  41. int n,m;
  42. while(cin>>m>>n &&(m+n)!=0 )
  43. {
  44. set_oil_map();
  45. input_oil_map(m,n);
  46. int count=0;
  47. for(int i=1 ;i<=m ;i++)
  48. for(int j=1 ;j<=n ;j++)
  49. {
  50. if(oil_map[i][j]==OIL )
  51. {
  52. search_oil_map(i,j);
  53. count++;
  54. }
  55. }
  56. cout<<count<<endl;
  57. }
  58. return 0;
  59. }
  60. /*Problem Description
  61. The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits.
  62. GeoSurvComp works with one large rectangular region of land at a time,
  63. and creates a grid that divides the land into numerous square plots.
  64. It then analyzes each plot separately, using sensing equipment to determine whether or not the plot contains oil.
  65. A plot containing oil is called a pocket. If two pockets are adjacent, then they are part of the same oil deposit.
  66. Oil deposits can be quite large and may contain numerous pockets.
  67. Your job is to determine how many different oil deposits are contained in a grid.
  68. Input
  69. The input file contains one or more grids.
  70. Each grid begins with a line containing m and n,
  71. the number of rows and columns in the grid, separated by a single space.
  72. If m = 0 it signals the end of the input; otherwise 1 <= m <= 100 and 1 <= n <= 100.
  73. Following this are m lines of n characters each (not counting the end-of-line characters).
  74. Each character corresponds to one plot, and is either `*‘,
  75. representing the absence of oil, or `@‘, representing an oil pocket.
  76. Output
  77. For each grid, output the number of distinct oil deposits.
  78. Two different pockets are part of the same oil deposit if they are adjacent horizontally,
  79. vertically, or diagonally. An oil deposit will not contain more than 100 pockets.
  80. */

来自为知笔记(Wiz)

附件列表

时间: 2024-11-05 16:53:24

hdu 1204 深搜的相关文章

hdu 1258(深搜)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1258 Sum It Up Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 4012    Accepted Submission(s): 2066 Problem Description Given a specified total t

HDU 2717 深搜第一题、

题意:求n到k的最小路径,  n有三种变法 n+1,n-1或者2*n: 贴个广搜的模版在这里把.... 总结一下:一般涉及到求最短路的话用深搜 1 #include<iostream> 2 #include<cstdio> 3 #include<algorithm> 4 #include<queue> 5 #include<cstring> 6 using namespace std; 7 const int qq=1e5+10; 8 int v

HDU 3720 深搜 枚举

DES:从23个队员中选出4—4—2—1共4种11人来组成比赛队伍.给出每个人对每个职位的能力值.给出m组人在一起时会产生的附加效果.问你整场比赛人员的能力和最高是多少. 用深搜暴力枚举每种类型的人选择情况.感觉是这个深搜写的很机智. 在vector中存结构体就会很慢.TLE.直接存序号就AC了.以后还是尽量少用结构体吧. #include<stdio.h> #include<string.h> #include<map> #include<vector>

HDU 1010 深搜+减枝

HDU 1010 /************************************************************************* > File Name: HDU1010.cpp > Author:yuan > Mail: > Created Time: 2014年11月05日 星期三 22时22分56秒 **********************************************************************

HDU 1010 深搜+奇偶剪枝

题目:http://acm.hdu.edu.cn/showproblem.php?pid=1010 贴个资料: http://acm.hdu.edu.cn/forum/read.php?tid=6158 奇偶剪枝: 对于从起始点 s 到达终点 e,走且只走 t 步的可达性问题的一种剪枝策略. 如下列矩阵 : 从任意 0 到达 任意 0,所需步数均为偶数,到达任意 1 ,均为奇数.反之亦然 所以有,若s走且只走 t 步可到达e,则必有t >= abs(s.x - e.x) + abs(s.y -

hdu 1010 深搜+剪枝

深度搜索 剪枝 还不是很理解 贴上众神代码 //http://blog.csdn.net/vsooda/article/details/7884772#include<iostream> #include<math.h> using namespace std; char map[10][10]; int N,M,T; int di,dj,escape; int dir[4][2]={{0,-1},{0,1},{1,0},{-1,0}}; void dfs(int x,int y,

【深搜加剪枝五】HDU 1010 Tempter of the Bone

Tempter of the BoneTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 64326    Accepted Submission(s): 17567 Problem Description The doggie found a bone in an ancient maze, which fascinated him a l

深搜基础题目 杭电 HDU 1241

HDU 1241 是深搜算法的入门题目,递归实现. 原题目传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1241 代码仅供参考,c++实现: #include <iostream> using namespace std; char land[150][150]; int p,q; void dfs(int x,int y){ land[x][y] = '*'; if(land[x-1][y]!= '@' && land[x+1]

hdu 1175 连连看 (深搜)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1175 题目大意:如果某两个相同的棋子,可以通过一条线连起来(这条线不能经过其它棋子)这样的两个棋子可以消掉.还有一个要注意的地方的就是转弯.转弯的次数不超过两次,这两个棋子才可以在棋盘上消去~ 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 using namespace std; 5 int