找石油
来源:互联网 发布:男士保湿 知乎 编辑:程序博客网 时间:2024/04/30 22:56
找石油
Time Limit:1000MS Memory Limit:65536K
Total Submit:311 Accepted:163
Description
自从上次使用了你做的软件,YJQ公司被我们成功打败。他们只好另寻出路,去挖石油。为了完全打败YJQ公司,我们要把他的所有行动都封锁掉。现在我,LKI,又找到了你,编一个程序求出一块地中有多少块石油。
Input
第一行是这块地的长度与宽度N与M,(1<=N,M<=1000),下面N行M列的N*M个字符不是“@”,就是“#”。“@”代表着这是石油,“#”代表着这不是石油。若两块石油相邻,则认为他们是一块石油。
Output
只有一行,石油的个数。
Sample Input
4 3@#@@#@##@@@#
Sample Output
3
var f:array[1..4,1..2]of longint; a:array[0..1000,0..1000]of longint; b:array[0..1000,0..1000]of boolean; i,j,n,m,ans:longint; x:ansistring;function check(x,y:longint):boolean; begin if (x>0)and(x<=n)and(y>0)and(y<=m)and(a[x,y]=0)and(b[x,y]=true) then exit(true); exit(false); end;procedure dfs(x,y:longint); var i:longint; begin b[x,y]:=false; for i:=1 to 4 do if check(x+f[i,1],y+f[i,2]) then dfs(x+f[i,1],y+f[i,2]); exit; end;begin readln(n,m); f[1,1]:=0; f[1,2]:=1; f[2,1]:=1; f[2,2]:=0; f[3,1]:=0; f[3,2]:=-1; f[4,1]:=-1; f[4,2]:=0; for i:=1 to n do begin readln(x); for j:=1 to length(x) do if x[j]='#' then a[i,j]:=1 else a[i,j]:=0; end; fillchar(b,sizeof(b),true); for i:=1 to n do for j:=1 to m do if (b[i,j])and(a[i,j]=0) then begin inc(ans); dfs(i,j); end; write(ans);end.
1 0
- 找石油
- SSL P1454 找石油
- 石油污染
- 石油套管
- 石油知识
- 石油合并
- 一桶石油有多少
- 美元與石油
- 中石油最赚钱
- 中石油网上申购
- 中石油中签公布
- 中石油中签号码
- 石油和信息
- 洛克菲勒:石油大王
- 中石油裁员
- 延长石油内幕
- 参观大庆石油科技馆
- Oil Deposits(石油问题)
- (笔记) A*启蒙
- 用gem5img.py卸载目录时Permission denied: '/run/user/112/gvfs'
- Android手机拍照识别名片SDK
- Android进阶之路
- 如何解决chrome flash 过期
- 找石油
- 构造函数与析构函数
- 数字段计数
- TCP流量控制与拥塞控制
- pandas做数据分析(五):统计相关函数
- 手机服务器的微架构(wifi互传)
- JSP的动作(一)
- 【数据迁移】Mysql 在线数据迁移的一点想法
- ImageMagic identify 获取图片尺寸