zoukankan      html  css  js  c++  java
  • Uva572

    https://vjudge.net/problem/UVA-572

    The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSurvCompworkswithonelargerectangularregionoflandatatime,andcreatesagridthatdivides 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 containsone 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 0 1 2 2

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 const int maxn=105;
     5 using namespace std;
     6 char a[maxn][maxn];
     7 int n,m;
     8 int vis[maxn][maxn];
     9 int xx[8]={1,1,0,-1,-1,-1,0,1};
    10 int yy[8]={0,1,1,1,0,-1,-1,-1};
    11 void dfs(int x,int y)
    12 {
    13     if(x<0||x>=m||y<0||y>=n)return;
    14     if(vis[x][y]||a[x][y]!='@')return;
    15     vis[x][y]=1;
    16     for(int i=0;i<8;i++)
    17         for(int j=0;j<8;j++)
    18         dfs(x+xx[i],y+yy[i]);
    19 }
    20 int main()
    21 {
    22     while(scanf("%d %d",&m,&n)==2,m,n)
    23     {
    24         for(int i=0;i<m;i++)
    25             scanf("%s",a[i]);
    26         int cnt=0;
    27         memset(vis,0,sizeof vis);
    28         for(int i=0;i<m;i++)
    29             for(int j=0;j<n;j++)
    30             if(a[i][j]=='@'&&!vis[i][j])
    31                 dfs(i,j),cnt++;
    32         printf("%d
    ",cnt);
    33     }
    34     return 0;
    35 }
  • 相关阅读:
    CI框架 QQ接口(第三方登录接口PHP版)
    linux定时任务的设置
    WEB服务器:Apache、Tomcat、JBoss、WebLogic、Websphere、IIS的区别与关系
    php专业面试总结
    php常用数学函数
    UVA 1428 Ping pong
    UVA 11988 Broken Keyboard (a.k.a. Beiju Text)
    UVA 11991 Easy Problem from Rujia Liu?
    UVA 11995 I Can Guess the Data Structure!
    UVA 10375 Choose and divide
  • 原文地址:https://www.cnblogs.com/zuiaimiusi/p/11069535.html
Copyright © 2011-2022 走看看