zoukankan      html  css  js  c++  java
  • hdu 1312 Red and Black

    集训第一场 B题

    dfs简单题 做完这题就撤,回来再继续做吧= =  水手加油~

     1 #include<cstdio>
     2 #include<string>
     3 
     4 int Count;
     5 int to[4][2] = {{-1,0},{1,0},{0,1},{0,-1}};
     6 int row,col;
     7 char room[1000][1000];
     8 void dfs(int i, int j)
     9 {
    10     Count++;
    11     room[i][j] = '#';
    12     for(int k = 0; k < 4; k++)
    13     {
    14         int r,c;
    15         r = i + to[k][0];
    16         c = j + to[k][1];
    17         if(room[r][c] == '.' && r < row && c < col && r >= 0 && c >= 0)
    18             dfs(r,c);  //如果可以,进入
    19     }
    20     return ;
    21 }
    22 
    23 int main()
    24 {
    25     freopen("input.txt","r",stdin);
    26     int i,j,x,y;
    27     while(~scanf("%d%d",&col,&row)&&(col||row))
    28     {
    29         Count=0;
    30         for(i = 0; i < row; i++)
    31             scanf("%s",room[i]); //坑爹的输入 原来没有空格
    32         for(i = 0; i < row; i++)
    33         {
    34             for(j = 0; j < col; j++)
    35             {
    36                 if(room[i][j] == '@')
    37                 {
    38                     x=i;
    39                     y=j;
    40                 }
    41             }
    42         }
    43         dfs(x,y);
    44         printf("%d
    ",Count);
    45     }
    46     return 0;
    47 }
  • 相关阅读:
    。。。。。。
    数据库
    python基础
    。。。。
    drf
    CRM笔记梳理
    人生苦短,我学PYTHON
    React的初步了解
    递归与迭代比较
    有没有大佬会很标准的三层架构
  • 原文地址:https://www.cnblogs.com/imLPT/p/3849499.html
Copyright © 2011-2022 走看看