搜索入门--hd 1241 搜索模板
来源:互联网 发布:ubuntu 32位iso下载 编辑:程序博客网 时间:2024/06/05 14:52
Oil Deposits
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 33493 Accepted Submission(s): 19462
Problem Description
The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSurvComp works with one large rectangular region of land at a time, and creates a grid that divides the land into numerous square plots. It then analyzes each plot separately, using sensing equipment to determine whether or not the plot contains oil. A plot containing oil is called a pocket. If two pockets are adjacent, then they are part of the same oil deposit. Oil deposits can be quite large and may contain numerous pockets. Your job is to determine how many different oil deposits are contained in a grid.
Input
The input file contains one or more grids. Each grid begins with a line containing m and n, the number of rows and columns in the grid, separated by a single space. If m = 0 it signals the end of the input; otherwise 1 <= m <= 100 and 1 <= n <= 100. Following this are m lines of n characters each (not counting the end-of-line characters). Each character corresponds to one plot, and is either `*', representing the absence of oil, or `@', representing an oil pocket.
Output
For each grid, output the number of distinct oil deposits. Two different pockets are part of the same oil deposit if they are adjacent horizontally, vertically, or diagonally. An oil deposit will not contain more than 100 pockets.
Sample Input
1 1*3 5*@*@***@***@*@*1 8@@****@*5 5 ****@*@@*@*@**@@@@*@@@**@0 0
Sample Output
0122
题解:贪心枚举每点即可
#include<iostream>using namespace std;#include<string.h>#include<algorithm>char map[101][101];int dir[2][8]={{-1,0,1,0,-1,-1,1,1},{0,-1,0,1,-1,1,-1,1}};//bool vis[101][101];int n,m;void dfs(int x,int y){ //vis[x][y]=false; map[x][y]='*'; for(int i=0;i<8;i++) { int dx=x+dir[0][i]; int dy=y+dir[1][i]; if(map[dx][dy]=='@'&&dx>=0&&dx<n&&dy>=0&&dy<m) dfs(dx,dy); } return ;}int main(){ while(cin>>n>>m) { if(n==0&&m==0) break; int ans=0; memset(map,0,sizeof(map)); for(int i=0;i<n;i++) for(int j=0;j<m;j++) cin>>map[i][j]; for(int i=0;i<n;i++) for(int j=0;j<m;j++) { if(map[i][j]=='@') { dfs(i,j); ans++; } } cout<<ans<<endl; } return 0;}
Sample Output
0122
阅读全文
0 0
- 搜索入门--hd 1241 搜索模板
- HD-27-水池数目(搜索)
- 搜索模板
- 【模板】搜索
- 【搜索入门】搜索字符串
- 搜索入门
- 搜索入门
- 搜索入门
- 搜索入门
- 搜索入门
- HDOJ1078 记忆化搜索入门题 有详细的记忆化搜索模板程序
- 模板:二分搜索技术
- 二分搜索模板
- A*启发式搜索 模板
- A*启发式搜索模板
- 模板--二叉搜索树
- 【搜索】【广搜模板】
- 三分搜索 模板
- Single Number leetcode java
- Sequence I
- 使用turtle库画蛇
- 爬虫之个人理解的基本处理思路
- leetcode657: Judge Route Circle
- 搜索入门--hd 1241 搜索模板
- 致即将毕业的你之每日一编-001
- Spring IoC底层原理
- Linux学习笔记--Python操作mysql数据库(封装基本的增删改查)
- 总结springmvc访问静态资源的三种方式
- 常用的数据字典
- 二分图
- hdu 6150
- 517_glide加载不出gif