zoukankan      html  css  js  c++  java
  • [恢]hdu 1312

    2011-12-26 09:19:37

    地址:http://acm.hdu.edu.cn/showproblem.php?pid=1312

    题意:在铺满红砖和黑砖的房间里,一个人每次只能移动到黑砖,问有多少个砖块是可达的。

    mark:bfs和dfs都可以。。。数据又很小,才20。

    代码:

    # include <stdio.h>
    # include <string.h>


    int ans, n, m ;
    char graph[30][30] ;
    int visited[30][30] ;


    void dfs(int x, int y)
    {
    int xx, yy, i;
    int tab[4][2] = {0, 1, 0, -1, 1, 0, -1, 0} ;
    visited[x][y] = 1 ;
    ans ++ ;
    for (i = 0 ; i < 4 ; i++)
    {
    xx = x + tab[i][0] ;
    yy = y + tab[i][1] ;
    if (xx < 0 || xx >= n || yy < 0 || yy >= m) continue ;
    if (visited[xx][yy] == 1) continue ;
    if (graph[xx][yy] == '#') continue ;
    dfs (xx, yy) ;
    }
    }


    int main ()
    {
    int i, j, sx, sy ;
    while (~scanf ("%d %d%*c", &m, &n) && (n||m))
    {
    for (i = 0 ; i< n ; i++)
    scanf ("%s%*c", graph[i]) ;
    for (i = 0 ; i < n ; i++)
    for (j = 0 ; j < m ;j++)
    {
    if (graph[i][j] == '@')
    sx = i, sy = j ;
    }
    memset (visited, 0, sizeof(visited)) ;
    ans = 0 ;
    dfs (sx, sy) ;
    printf ("%d\n", ans) ;
    }
    return 0 ;
    }



  • 相关阅读:
    to_char &&to_date
    java中Integer 与 String 类型的 相互 转换
    group by 的用法
    谈 计算时间的天数差
    领域建模
    Java Classloader详解
    阿里巴巴Java招聘
    Maven Archetype
    负载均衡
    Maven
  • 原文地址:https://www.cnblogs.com/lzsz1212/p/2315357.html
Copyright © 2011-2022 走看看