猴群(normal)

猴群(normal)

Time Limit:1000MS  Memory Limit:65536K
Total Submit:101 Accepted:45

Description

输入一个矩阵(n*m),由0~9组成,其中数字0代表树,1~9代表猴子,凡是群居在一起的猴子称之为一群猴子。现在要你找出当中有多少只猴子。

Input

第一行两个整数n,m。(n<=1000;m<=1000)
接下来是一个n*m的矩阵。含义见题目描述。

Output

一个整数,表明有多少群猴子。

Sample Input

4 10
0234500067
1034560500
2045600671
0000000089

Sample Output

4

Source

Fstephen




  • var
      a:array[-1..10000,-1..10000]of boolean;
      i,j,n,m,tot:longint;
    
    procedure init;
    var
      i,j:longint;
      ch:char;
      s:string;
    begin
      readln(n,m);
      for i:=1 to n do
      begin
        for j:=1 to m do
        begin
          read(ch);
          if ord(ch)>ord('0') then a[i,j]:=true;
        end;
        readln;
      end;
    end;
    procedure ppp(x,y:longint);
    begin
      a[i,j]:=false;
    end;
    procedure pp(x,y:longint);
    var
      i,j:longint;
    begin
      a[x,y]:=false;
      if a[x+1,y] then pp(x+1,y);
      if a[x-1,y] then pp(x-1,y);
      if a[x,y+1] then pp(x,y+1);
      if a[x,y-1] then pp(x,y-1);
    end;
    begin
        init;
      for i:=1 to n do
        for j:=1 to m do
          begin
            if a[i,j] then begin pp(i,j); inc(tot);end;
          end;
      writeln(tot);
    end.
    
    
    





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值