zoukankan      html  css  js  c++  java
  • FloodZJFC Weekly 5

     

    题目描述

    The Flood come from the border of the map, so tell me the area without flood...Do u think it's easy ?

    输入描述

        First T(<=100) as T case...
    Then M(<=100),N(<=100) as the size of Map...
    Then the map coming...
    '#' as the wall and it's enough high to against flood
    '.' as the land

    输出描述

        Show the number of the point without flood...

    样例输入

    2
    3 3
    .#.
    #.#
    .#.
    4 4
    ####
    #..#
    #..#
    ####

    样例输出

    1
    4

    比较easy的搜索题,有一种比较好的方法是在地图边缘添点,然后在(0,0)处开始搜索,记录被淹过的面积以及大坝的总长,最后相减得到未淹过的面积。当然也可以遍历每个未被访问的陆地,对每个点实行宽搜,如果宽搜中出现越界的判定,则说明未被大坝包围,否则记录在改次搜索中结点的总数,最后累加得到结果。

    我的代码写的比较麻烦,对4个边界上的点进行深搜,并处理(将访问到的“.”--->"#"),最后统计地图中"."的个数并是结果了

    代码如下:

    Code
  • 相关阅读:
    闲谈随笔以及对自己的心里暗示
    java利用Scanner获取键盘输入
    【积累】发送验证码按钮倒计时js
    【积累】validate验证框架的使用
    重写toString()方法来描述一个类
    【java基础】 合并两个类型相同的list
    java单例类/
    基本类型的包装类
    强转
    【java基础】面向对象的三大特征---多态
  • 原文地址:https://www.cnblogs.com/pandy/p/1447641.html
Copyright © 2011-2022 走看看