hdu 1241 Oil Deposits
来源:互联网 发布:数据透视分析表怎么用 编辑:程序博客网 时间:2024/05/29 13:31
Oil Deposits
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 11241 Accepted Submission(s): 6549
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
<span style="font-size:18px;">#include<iostream>#include<queue>const int MAX=100;int k[8][2]={{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};using namespace std;typedef struct oil{ int x; int y;};char map[MAX][MAX];int n;int m;void bfs(int x,int y){ int i,j; queue<oil>que; oil in,out; in.x=x; in.y=y; que.push(in); while(!que.empty()) { in=que.front(); que.pop(); oil next; for(i=0;i<8;i++) { next.x=out.x=in.x+k[i][0]; next.y=out.y=in.y+k[i][1]; if(next.x<1||next.x>n||next.y<1||next.y>m) continue; if(map[next.x][next.y]=='@') { map[next.x][next.y]='*'; bfs(next.x,next.y); } } }}int main(){ int i,j,sum; while(cin>>n>>m,m) { sum=0; for(i=1;i<=n;i++) { for(j=1;j<=m;j++) { cin>>map[i][j]; } } for(i=1;i<=n;i++) { for(j=1;j<=m;j++) { if(map[i][j]=='@') { sum+=1; map[i][j]='*'; bfs(i,j); } } } cout<<sum<<endl; } return 0;}</span>
0 0
- HDU 1241Oil Deposits
- HDU---1241Oil Deposits
- Hdu 1241 Oil Deposits
- Hdu 1241 - Oil Deposits
- HDU-1241:Oil Deposits
- hdu 1241 Oil Deposits
- hdu 1241 Oil Deposits
- hdu 1241 Oil Deposits
- hdu - 1241 - Oil Deposits
- HDU-1241Oil Deposits
- hdu 1241 Oil Deposits
- hdu 1241 Oil Deposits
- HDU 1241 Oil Deposits
- hdu 1241 Oil Deposits
- hdu 1241 Oil Deposits
- HDU 1241 Oil Deposits
- hdu-1241-Oil Deposits
- hdu 1241 Oil Deposits
- hdu 1075
- C#开发Android-文件的读写
- 写了一个程序,分析各个源文件之间的include关系。
- POJ 3176:Cow Bowling
- Android写通讯录 用到的数据库知识
- hdu 1241 Oil Deposits
- 剑指offer面试题13扩展:带头指针的单链表的操作
- 通过端口 1433 连接到主机 localhost 的 TCP/IP 连接失败。错误:“Connection refused: connect。
- Etherpeek监听UDP报文时间戳获取
- libsvm工具箱C++下编程实践1
- ruby on rails学习(一)
- 三种创建二叉树的方式
- 盘位wi为什止得知蹿
- 大牛很通俗地介绍《信号与系统》