死者之魂推动遇难船

样例输入

6 8 4
11111001
11001001
00101001
10010001
10000001
11111111
 

样例输出

11111001
11001001
22101221
12212221
12222221 
​11111111

数据范围限制

【数据范围】
20%的数据保证,N,M≤10。
60%的数据保证,N,M≤100。
100%的数据保证,N,M≤1000,1≤H≤N+1。

 

Bfs每次找到一个船的最边边,如果有缺口就可以让水进来,然后有空而且不超过水的高度就可以让水进去

 

const
       fx:array[1..4,1..2]of longint=
       ((-1,0),(0,1),(1,0),(0,-1));
var
       map:array[0..1001,0..1001]of longint;
       f:array[0..1000000,1..2]of longint;
       n,m,h,i,j:longint;
       s:ansistring;
procedure go(x,y:longint);
var
       i,j,xx,yy,k:longint;
begin
       fillchar(f,sizeof(f),0);
       i:=0;
       j:=1;
       f[1,1]:=x;
       f[1,2]:=y;
       while i<j do
       begin
                inc(i);
                for k:=1 to 4 do
                begin
                       xx:=f[i,1]+fx[k,1];
                        yy:=f[i,2]+fx[k,2];
                        if map[xx,yy]=3 then
                        begin
                                inc(j);
                                f[j,1]:=xx;
                                f[j,2]:=yy;
                                map[xx,yy]:=2;
                        end;
                end;
       end;
end;
begin
       assign(input,'cruise.in');reset(input);
       assign(output,'cruise.out');rewrite(output);
       readln(n,m,h);
       for i:=n downto 1 do
       begin
                readln(s);
                for j:=1 to m do
                         map[i,j]:=ord(s[j])-48;
       end;
       for i:=1 to h do
                for j:=1 to m do
                        if map[i,j]=0 then
                                map[i,j]:=3;
       for i:=1 to m do
       begin
                if map[1,i]=3 then
                begin
                        map[1,i]:=2;
                        go(1,i);
                end;
                if map[n,i]=3 then
                begin
                        map[n,i]:=2;
                        go(n,i);
                end;
       end;
       if h>n then
                h:=n;
       for i:=1 to h do
       begin
               if map[i,1]=3 then
                begin
                        map[i,1]:=2;
                        go(i,1);
                end;
                if map[i,m]=3 then
                begin
                        map[i,m]:=2;
                        go(i,m);
                end;
       end;
       for i:=n downto 1 do
       begin
                for j:=1 to m do
                        if map[i,j]=3 then
                                write(0)
                        else
                                write(map[i,j]);
                writeln;
       end;
       close(input);close(output);
end.

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值