HDU-1241 Oil Deposits 【dfs】
来源:互联网 发布:pdf锐化软件 编辑:程序博客网 时间:2024/05/22 14:52
Oil Deposits
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 34878 Accepted Submission(s): 20251
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
dfs入门 每判断一个坑就把那个坑变成石头
#include<bits/stdc++.h>using namespace std;int m,n;char G[107][107];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){ G[x][y] = '*'; for(int i = 0; i < 8; i++) { int dx = x+dir[i][0]; int dy = y+dir[i][1]; if(G[dx][dy]=='@' && dx>=1 && dx<=m && dy>=1 && dy<=n) dfs(dx,dy); }}int main(){ while(cin>>m>>n) { if(m == 0) break; int ans = 0; for(int i = 1; i <= m; i++) cin>>G[i]+1; for(int i = 1; i <= m; i++) for(int j = 1; j <= n; j++) { if(G[i][j] == '@') { dfs(i,j); ans++; } } cout<<ans<<endl; } return 0;}
阅读全文
0 0
- hdu 1241 Oil Deposits (dfs)
- HDU-1241 Oil Deposits (DFS)
- HDU 1241 Oil Deposits (DFS)
- 【DFS】hdu:1241 Oil Deposits
- hdu 1241dfs Oil Deposits
- hdu 1241 Oil Deposits(DFS)
- HDU--1241:Oil Deposits (DFS)
- HDU 1241 Oil Deposits 【DFS】
- HDU 1241 Oil Deposits(dfs)
- HDU 1241 -- Oil Deposits (dfs)
- HDU 1241--Oil Deposits【DFS】
- HDU 1241 Oil Deposits(DFS)
- [dfs]HDU 1241 Oil Deposits
- HDU 1241 Oil Deposits DFS
- DFS-HDU-1241-Oil Deposits
- hdu 1241 Oil Deposits(dfs)
- hdu 1241 Oil Deposits(DFS)
- HDU-1241-Oil Deposits【DFS】
- HDU-2577 How to Type (线性状态dp)
- 数据结构--单向链表2
- 转载logback简要用法 原文地址https://www.cnblogs.com/warking/p/5710303.html
- Kafka
- 【STL】vector小结
- HDU-1241 Oil Deposits 【dfs】
- hdu 2141
- React list this.props.children
- 29-多线程(线程间通信-多生产者多消费者问题-JDK1.5新特性-Condition).1 2 31-多线程(线程间通信-多生产者多消费者问题-JDK1.5解决办法-范例). 1 2
- PHP数组以中文首字母来排序
- 编写一个程序,可以一直接收键盘字符,如果是小写字符就输出对应的大写字符,如果接收的是大写字符,就输出对应的小写字符,如果是数字不输出
- Ubuntu 16.04部署FTP 安装vsftpd
- Hadoop实战(8)_CDH添加Hive服务及Hive基础
- Hive安装配置使用及java api调用