Codeforces847I NoiseLevel

标签:bfs,队列

TheBerland's capital has the form of a rectangle with sizes n × m quarters. Allquarters are divided into three types:

·  regular (labeled with the character '.') — such quarters do not produce the noisebut are not obstacles to the propagation of the noise;

·  sources of noise (labeled with an uppercaseLatin letter from 'A' to 'Z') — such quarters are noise sources and arenot obstacles to the propagation of the noise;

·  heavily built-up (labeled with the character'*') — such quarters are soundproofed,the noise does not penetrate into them and they themselves are obstacles to thepropagation of noise.

A quarterlabeled with letter 'A' produces q units of noise. Aquarter labeled with letter 'B' produces 2·q units of noise. Andso on, up to a quarter labeled with letter 'Z', which produces 26·q units ofnoise. There can be any number of quarters labeled with each letter in thecity.

Whenpropagating from the source of the noise, the noise level is halved when movingfrom one quarter to a quarter that shares a side with it (when an odd number isto be halved, it's rounded down). The noise spreads along the chain. Forexample, if some quarter is located at a distance 2 from the noise source, then the value of noise which willreach the quarter is divided by 4. So thenoise level that comes from the source to the quarter is determined solely bythe length of the shortest path between them. Heavily built-up quarters areobstacles, the noise does not penetrate into them.


 The values in the cells of the table on the right show the totalnoise level in the respective quarters for q = 100, the first termin each sum is the noise from the quarter 'A', the second — the noise from thequarter 'B'.

The noiselevel in quarter is defined as the sum of the noise from all sources. To assessthe quality of life of the population of the capital of Berland, it is requiredto find the number of quarters whose noise level exceeds the allowed levelp.

Input

The firstline contains four integers nmq and p (1 ≤ n, m ≤ 250, 1 ≤ q, p ≤ 106) — thesizes of Berland's capital, the number of noise units that a quarter 'A' produces, and the allowable noise level.

Each ofthe following n linescontains m characters— the description of the capital quarters, in the format that was described inthe statement above. It is possible that in the Berland's capital there are noquarters of any type.

Output

Print thenumber of quarters, in which the noise level exceeds the allowed level p.

Example

Input

3 3 100 140
...
A*.
.B.

Output

3

Input

3 3 2 8
B*.
BB*
BBB

Output

4

Input

3 4 5 4
..*B
..**
D...

Output

7

Note

Theillustration to the first example is in the main part of the statement.

直接用队列模拟bfs,模板题

Code

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int maxn=305;
 
char st[maxn][maxn];
int x[maxn*maxn],y[maxn*maxn],z[maxn*maxn];
int was[maxn][maxn],noise[maxn][maxn];
int n,m,q,p,cnt=0;
int main()
{
       cin>>n>>m>>q>>p;
       rep(i,0,n-1)scanf("%s",st[i]);
       rep(i,0,n-1)
           rep(j,0,m-1)
                  if(st[i][j]>='A'&&st[i][j]<='Z'){
                         inttemp=(st[i][j]-'A'+1)*q;
                         inthead=0,tail=1;
                         x[0]=i,y[0]=j,z[0]=temp;
                         was[i][j]=++cnt;
                         while(head<tail){
                                noise[x[head]][y[head]]+=z[head];
                                if(z[head]>=2)
                                       rep(j,0,3){
                                              intxnow=x[head]+dx[j],ynow=y[head]+dy[j];
                                              if(xnow>=0&&ynow>=0&&xnow<n&&ynow<m)
                                                     if(st[xnow][ynow]!='*'&&was[xnow][ynow]!=cnt){
                                                            x[tail]=xnow,y[tail]=ynow,z[tail]=z[head]>>1;
                                                            was[xnow][ynow]=cnt;tail++;
                                                     }
                                       }
                                head++;
                         }
                 }
       intans=0;
       rep(i,0,n-1)
           rep(j,0,m-1)if(noise[i][j]>p)ans++;
       cout<<ans<<endl;
       return0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
【疯狂模渲大师不限时间版】辅助。疯狂模渲大师,是一个大型综合性的辅助,而疯狂模渲大师不限时间版,是疯狂模渲大师作者食住玩为粉丝所出的一个可以无需在线/离线登陆、随意共享的更新版本。作者开发更新了疯狂模渲大师的这个版本,共享给暂时不能入手疯狂模渲大师VIP/SVIP等型号的设计师。 【疯狂模渲大师不限时间版】,横跨14个大菜单:辅助篇、场景篇、建模篇、图形篇、二维篇、灯光篇、材质篇、贴图篇、视显篇、渲染篇、景观篇、建筑动画,等大菜单,下辖近300个一键建模、渲染等功能命令的小辅助。而在疯狂模渲大师VIP以上级别型号中,主要以室内设计为重,舍弃了3dmax插件神器终结版中诸多的园林景观建筑动画之类的功能。 疯狂模渲大师|为什么是最权威的超一流大型辅助? 是全球唯一专精于室内3dmax效果图设计领域的超一流最大型辅助,而且疯狂模渲大师走出了国门: 它走出了国门: 疯狂模渲大师,是在3dmax辅助领域,唯一能走出国门的。   还记得那是2017年的某天,也是食住玩第一次见到纯英文的win8系统,要不是会英文,差点无法远程处理当时旧版本与那位新加坡用户操作系统的一点小问题。   (2018年才正式更名为“疯狂模渲大师”,多年来换了不少名字,2018年后就没再换了)   例如,2017年第一位国外用户来自新加坡,远程协助她电脑系统的截图留念,可查阅相关资讯。 疯狂模渲大师-主要解决了: \> 3dmax在室内外效果图设计的场景维护、建模(单面、双面、彩平图)、常用技巧、编辑(二维和三维)、灯光(智能)、材质贴图、相机(标准、VR、CR)、工具、全屋定制、户外、渲染(批处理、自动关机、多样化渲染加速、全景小视频生长动画等)、实用修改器、资源数据管理(模型截面材质贴图入库)等13大领域。 疯狂模渲大师的优势: 为3dmax提供了专门针对室内效果图设计的最对称辅助,此外也搭配了全屋定制、室外设计等功能版块,为多栖设计师节省了宝贵的作图时间,革新了绘图工作者传统的繁琐操作,有效提升了极大的工作效率。 疯狂模渲大师-主要作用:  1个\[疯狂模渲大师\],全垒打3dmax各方面的问题。两点一线、告别繁琐操作,使零基础速成3dmax、让室内3dmax效果图大师能如虎添翼。   \> 有效缩短了实习生与菜鸟对3dmax的学习时间、显著提升了3dmax效果图设计师和绘图员(专职、在家副业)的工作效率。                                                                                                                               疯狂模渲大师-倍速提高效率: 为设计师节省了宝贵的作图时间不说,更是提高了实习生学习的效率、减少了实习生实习的时间。 疯狂模渲大师一直致力于提高设计师的工作效率,更加为绘图者的便利操作持续努力着! 希望广大设计工作者,遇到问题要沉着应对,不要心浮气躁。要知道,找准所遇到3dmax问题的解决方法,才能把问题处理好。“病急乱投医”的做法,是不可取的。                                                                        电脑系统运行环境: 软件名称:3dmax疯狂模渲大师 操作平台: 系统环境:Windows(X64) 支持环境:3dsMax 2012以上| Vray2.0以上 |Corona1.7以上 兼容软件语言:多国语言(建议中文) 为什么必须是3dmax2012以上? 3dmax疯狂模渲大师(当时还不叫疯狂模渲大师的第一个收米版本)正式公开推行给广大绘图工作者的时间是2012年,所以需要装载3dmax2012以上的软件版本。 软件版本:疯狂模渲大师4.0 软件大小:2.86 GB 软件脚本:MAXscript、Python(版本未知) 软件分类:三维建模渲染、全景效果图、小视频动画制作 渲染器:Gpu、VRay、Corona Renderer
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值