zoukankan      html  css  js  c++  java
  • poj 1562 Oil Deposits

    Oil Deposits
    Time Limit: 1000MS   Memory Limit: 10000K
    Total Submissions: 13505   Accepted: 7345

    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 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

    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

    0
    1
    2
    2
    

    Source

     
     
    分析:
    只有map[i][j]==0,该位置是新的oil deposit。然后广搜。
     1 #include<iostream>
     2 #include<queue>
     3 #include<cstdio>
     4 #include<cstring>
     5 using namespace std;
     6 int m,n;
     7 short map[105][105];
     8 short dir[8][2]={{-1,-1},{-1,0},{-1,1},{0,1},{1,1},{1,0},{1,-1},{0,-1}};
     9 bool check(int x,int y){
    10     if(x<0||x>=m||y<0||y>=n||map[x][y])
    11     return false;
    12     return true;
    13 }
    14 int main(){
    15     while(scanf("%d%d",&m,&n)&&m!=0&&n!=0){
    16         memset(map,0,sizeof(map));
    17         int i,j;
    18         for(i=0;i<m;i++){
    19             for(j=0;j<n;j++){
    20                 char c;
    21                 cin>>c;
    22                 if(c=='*'){
    23                     map[i][j]=-1;
    24                 }
    25                 else{
    26                     map[i][j]=0;
    27                 }
    28             }
    29         }
    30         //cout<<1<<endl;
    31         /*for(i=0;i<m;i++){
    32             for(j=0;j<n;j++){
    33                 cout<<map[i][j]<<endl;
    34             }
    35         }*/
    36         int count=0;
    37         for(i=0;i<m;i++){
    38             for(j=0;j<n;j++){
    39                 if(map[i][j]==0){
    40                 queue<int> q;
    41                 q.push(i*100+j);
    42                 map[i][j]=++count;
    43                 while(!q.empty()){
    44                     short x=q.front()/100;
    45                     short y=q.front()%100;
    46                     q.pop();
    47                     int k;
    48                     for(k=0;k<8;k++){
    49                         short xx=x+dir[k][0];
    50                         short yy=y+dir[k][1];
    51                         if(check(xx,yy)){
    52                             q.push(xx*100+yy);
    53                             map[xx][yy]=map[x][y];
    54                         }
    55                     }
    56                 }    
    57                 }
    58             }
    59         }
    60         /*for(i=0;i<m;i++){
    61             for(j=0;j<n;j++){
    62                 cout<<map[i][j]<<endl;
    63             }
    64         }*/
    65         cout<<count<<endl;
    66     }
    67     return 0;
    68 }
  • 相关阅读:
    oracle之rman备份
    oracle数据库经常提示27102 out of memory解决方法
    异构环境oracle数据库迁移dmp文件之exp和imp以及expdp和impdp
    新安装的win7/win10系统,所有驱动都没安装,插入U盘也无法识别解决方法
    oracle使用一条语句批量插入多条数据
    oracle使用flashback时,没有显示undosql
    export的变量另开一个终端失效解决方法
    oracle服务器重启后无法进入系统,登录系统时提示model is unknow
    mysql将某数据库的全部权限赋给某用户,提示1044错误Access denied
    如何取消noarch.rpm包
  • 原文地址:https://www.cnblogs.com/Deribs4/p/4282987.html
Copyright © 2011-2022 走看看