• 拯救OIBH总部


    题意

    OIBH被突来的洪水淹没了>.<还好OIBH总部有在某些重要的地方起一些围墙,用*号表示,而一个封闭的*号区域洪水是进不去的……现在给出OIBH的围墙建设图,问OIBH总部没被淹到的重要区域(由"0"表示)有多少。


    分析

    做法,周围一圈撒“种子”,然后将能蔓延的全部遍历掉就行了


    var
    zfc:ansistring;
    i,j,x,y,tj:longint;
    a:array[-1..501,-1..501]of char;


    procedure s(i,j:longint);
    var
    w:longint;
    begin
        if a[i,j]='0' then a[i,j]:='1' else exit;
        s(i+1,j);
        s(i-1,j);
        s(i,j+1);
        s(i,j-1);
    end;




    begin
        while not eof(input) do
        begin
            read(zfc);
            readln;
            inc(i);
            for j:=1 to length(zfc) do
            a[i,j]:=zfc[j];
            y:=length(zfc);
        end;
        x:=i;
        for i:=1 to x do
        begin
            if a[i,1]='0' then s(i,1);
            if a[i,y]='0' then s(i,y);
        end;
        for i:=1 to y do
        begin
            if a[1,i]='0' then s(1,i);
            if a[x,i]='0' then s(x,i);
        end;
        for i:=1 to x do
        for j:=1 to y do
        if a[i,j]='0' then inc(tj);
        writeln(tj);
    end.

  • 相关阅读:
    【Vijos1159】岳麓山上打水 [迭代加深]
    【POJ3134】 Power Calculus [迭代加深]
    【2019.1.24】 搜索,动规 经典题目体验赛
    【noip2017】
    【poj3311】Hie With The Pie [状压dp]
    [bzoj3938] [Uoj #88] Robot
    [洛谷P4707] 重返现世
    [洛谷P4097] [HEOI2013] Segment
    KD-tree 学习小记
    NOI2019 酱油记
  • 原文地址:https://www.cnblogs.com/YYC-0304/p/9500153.html
Copyright © 2020-2023  润新知