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

    http://poj.org/problem?id=1562

    只想问一句,还敢更坑么?每一行数据后都可能有多个空格。。

     1 #include <stdio.h>
     2 #include <string.h>
     3 #include <stdlib.h>
     4 int m,n;
     5 char map[102][102];
     6 void find(int *x,int *y)
     7 {
     8     int i,j;
     9     for(i=1;i<=m;i++) 
    10         for(j=1;j<=n;j++)
    11             if(map[i][j]=='@') {
    12                 *x=i;
    13                 *y=j;
    14                 return;
    15             }
    16 }
    17 bool check(int x,int y)
    18 {
    19     if(1<=x&&x<=m&&1<=y&&y<=n)    return true;
    20     return false;
    21 }
    22 void dfs(int x,int y)
    23 {
    24     if(!check(x,y))    return;
    25     if(map[x][y]!='@')    return;
    26     map[x][y]='*';
    27     dfs(x-1,y-1);
    28     dfs(x,y-1);
    29     dfs(x+1,y-1);
    30     dfs(x-1,y);
    31     dfs(x+1,y);
    32     dfs(x-1,y+1);
    33     dfs(x,y+1);
    34     dfs(x+1,y+1);
    35 }
    36 int main()
    37 {
    38     while(scanf("%d%d",&m,&n)!=EOF) {
    39         if(m==n&&m==0)    return 0;
    40         int i,j;
    41         char ch;
    42         while(ch=getchar()!='\n')    ;    
    43         for(i=1;i<=m;i++) {
    44             for(j=1;j<=n;j++) {
    45                 scanf("%c",&map[i][j]);
    46             }
    47             while(ch=getchar()!='\n')    ;
    48         }
    49         int x=-1,y=-1;
    50         find(&x,&y);
    51         int total_field=0;
    52         while(check(x,y)) {
    53             total_field++;
    54             dfs(x,y);
    55             x=y=-1;
    56             find(&x,&y);
    57         }
    58         printf("%d\n",total_field);
    59     }
    60     return 0;
    61 }
  • 相关阅读:
    ZendFramwork配置
    JS控制页面前进、后退
    PHP乱码
    php 文件和表单内容一起上传
    mysqli常用命令
    图解SQL多表关联查询
    mysql默认字符集修改
    mysql控制台命令
    Nanami's Digital Board

  • 原文地址:https://www.cnblogs.com/yangce/p/2903305.html
Copyright © 2011-2022 走看看