hdoj 1241 Oil Deposits
Oil Deposits
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 16542 Accepted Submission(s):
9500
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.
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.
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.
- /*
- 题意:给你一个规格为n*m的矩阵,由
- 字符'@'和'*'组成,问所有的@组成的区域
- 有多少块,(@组成的区域指向它的八个方向中其中一个方向
- 走依然是@)
- 题解:先找到第一个@,然后向这个@的八个方向查找,将所有查找到的
- @都替换为*(将找过的位置覆盖,避免重复查找),看最后调用了dfs函数
- 多少次,就有多少个区域
- */
- #include<stdio.h> ///hdu1241
- #include<string.h>
- #include<algorithm>
- #define MAX 110
- #define INF 0x3f3f3f
- char map[MAX][MAX];
- int n,m;
- void dfs(int x,int y)
- {
- int i,j;
- int move[8][2]={1,0,-1,0,0,1,0,-1,1,-1,1,1,-1,1,-1,-1};
- if(map[x][y]=='@'&&0<=x&&x<n&&0<=y&&y<m)
- {
- map[x][y]='*';
- for(i=0;i<8;i++)//搜索八个方向
- dfs(x+move[i][0],y+move[i][1]);
- //可以用上边的辅助数组进行搜索 ,也可以直接按照下边注释的
- //方法搜索,其原理相同
- // dfs(x-1,y);
- // dfs(x+1,y);
- // dfs(x,y-1);
- // dfs(x,y+1);
- // dfs(x-1,y-1);
- // dfs(x-1,y+1);
- // dfs(x+1,y-1);
- // dfs(x+1,y+1);
- }
- return ;
- }
- int main()
- {
- int j,i,t,k;
- while(scanf("%d%d",&n,&m),n|m)
- {
- for(i=0;i<n;i++)
- scanf("%s",map[i]);
- int sum=0;
- for(i=0;i<n;i++)
- {
- for(j=0;j<m;j++)
- {
- if(map[i][j]=='@')
- {
- dfs(i,j);
- sum++;
- }
- }
- }
- printf("%d\n",sum);
- }
- return 0;
- }
hdoj 1241 Oil Deposits的更多相关文章
- HDOJ(HDU).1241 Oil Deposits(DFS)
HDOJ(HDU).1241 Oil Deposits(DFS) [从零开始DFS(5)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架 ...
- HDU 1241 Oil Deposits --- 入门DFS
HDU 1241 题目大意:给定一块油田,求其连通块的数目.上下左右斜对角相邻的@属于同一个连通块. 解题思路:对每一个@进行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 Oil Deposits(石油储藏)
HDU 1241 Oil Deposits(石油储藏) 00 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Probl ...
- DFS(连通块) HDU 1241 Oil Deposits
题目传送门 /* DFS:油田问题,一道经典的DFS求连通块.当初的难题,现在看上去不过如此啊 */ /************************************************ ...
- HDOJ/HDU 1241 Oil Deposits(经典DFS)
Problem Description The GeoSurvComp geologic survey company is responsible for detecting underground ...
- hdu 1241:Oil Deposits(DFS)
Oil Deposits Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total ...
- 杭电1241 Oil Deposits
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission ...
- HDU 1241 Oil Deposits DFS(深度优先搜索) 和 BFS(广度优先搜索)
Oil Deposits Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...
随机推荐
- c++ 重定位输出到DOS
#define USE_WIN32_CONSOLE int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTST ...
- Eclipse 启动问题:'Initilizing Java Tooling' has encountered a problem(。。。)
一.问题描述: . 二.分析及解决 ...
- 1003: [ZJOI2006]物流运输trans
spfa+dp; 刚刚开始一直想不通怎么判断他是否换了道: 后来才知道,将那个时间段打包,找出这段时间内的最短路: 真是太奇妙了! #include<cstdio> #include< ...
- HDU 1160 FatMouse's Speed(DP)
点我看题目 题意 :给你好多只老鼠的体重和速度,第 i 行代表着第 i 个位置上的老鼠,让你找出体重越大速度越慢的老鼠,先输出个数,再输出位置. 思路 :看题的时候竟然脑子抽风了,看了好久愣是没明白题 ...
- 实时时钟、系统时钟和CPU时钟的区别
http://blog.sina.com.cn/s/blog_68f909c30100pli7.html 实时时钟:RTC时钟,用于提供年.月.日.时.分.秒和星期等的实时时间信息,由后备电池供电,当 ...
- linux多线程驱动中调用udelay()对整个系统造成的影响(by liukun321咕唧咕唧)
以前没考虑过这个问题,而且之前可能运气比较好,虽然用了udelay但也没出什么奇怪的问题,今天在 CSDN上看到了一篇关于此问题帖子,觉得很受用,再此做简要的记录和分析: 驱动开的是内核线程 跟普通进 ...
- C++11 中的线程、锁和条件变量
转自:http://blog.jobbole.com/44409/ 线程 类std::thread代表一个可执行线程,使用时必须包含头文件<thread>.std::thread可以和普通 ...
- BZOJ_1612_[Usaco2008_Jan]_Cow_Contest_奶牛的比赛_(dfs)
描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1612 \(n\)头奶牛比赛,给出一些胜负情况,问可以确定多少头奶牛的排名. 分析 无论胜负,只 ...
- NOI2010超级钢琴 2
2006: [NOI2010]超级钢琴 Time Limit: 20 Sec Memory Limit: 552 MBSubmit: 1296 Solved: 606[Submit][Status ...
- 使用console进行性能测试和计算代码运行时间
对于前端开发人员,在开发过程中经常需要监控某些表达式或变量的值,如果使用用debugger会显得过于笨重,最常用的方法是会将值输出到控制台上方便调试.最常用的语句就是console.log(expre ...