博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Noise Level CodeForces - 847I
阅读量:4582 次
发布时间:2019-06-09

本文共 4065 字,大约阅读时间需要 13 分钟。

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

  • regular (labeled with the character '.') — such quarters do not produce the noise but are not obstacles to the propagation of the noise;
  • sources of noise (labeled with an uppercase Latin letter from 'A' to 'Z') — such quarters are noise sources and are not 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 the propagation of noise.

A quarter labeled with letter 'A' produces q units of noise. A quarter labeled with letter 'B' produces q units of noise. And so on, up to a quarter labeled with letter 'Z', which produces 26·q units of noise. There can be any number of quarters labeled with each letter in the city.

When propagating from the source of the noise, the noise level is halved when moving from one quarter to a quarter that shares a side with it (when an odd number is to be halved, it's rounded down). The noise spreads along the chain. For example, if some quarter is located at a distance 2 from the noise source, then the value of noise which will reach the quarter is divided by 4. So the noise level that comes from the source to the quarter is determined solely by the length of the shortest path between them. Heavily built-up quarters are obstacles, the noise does not penetrate into them.

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

The noise level in quarter is defined as the sum of the noise from all sources. To assess the quality of life of the population of the capital of Berland, it is required to find the number of quarters whose noise level exceeds the allowed level p.

Input

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

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

Output

Print the number 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

The illustration to the first example is in the main part of the statement.

题解:普通的BFS,不过别忘了剪枝:噪声降低到0后,就返回。

1 #include
2 using namespace std; 3 4 struct node{ 5 int x,y,step; 6 node(int x,int y,int step):x(x),y(y),step(step){}; 7 }; 8 9 int n,m,nq,np;10 int dx[4]={
0,1,0,-1},dy[4]={
1,0,-1,0};11 int sum[255][255];12 bool vis[255][255];13 char m_map[255][255];14 15 void BFS(int From,int To){16 memset(vis,false,sizeof(vis));17 queue
q;18 vis[From][To]=true;19 int temp=((m_map[From][To]-'A')+1)*nq;20 21 q.push(node(From,To,temp)); 22 while(!q.empty()){23 node p=q.front();24 q.pop();25 if(p.step<=0) continue; //more important!!!!!!!26 for(int i=0;i<4;i++){27 int mx=p.x+dx[i],my=p.y+dy[i];28 if(mx<0||mx>=n||my<0||my>=m||vis[mx][my]||m_map[mx][my]=='*') continue;29 vis[mx][my]=true;30 sum[mx][my]+=p.step/2;31 q.push(node(mx,my,p.step/2));32 }33 }34 sum[From][To]+=temp;35 }36 37 void Solve(){38 int cnt=0; 39 for(int i=0;i
np) cnt++;42 printf("%d\n",cnt);43 }44 45 int main()46 { scanf("%d%d%d%d",&n,&m,&nq,&np);47 for(int i=0;i
='A'&&m_map[i][j]<='Z') BFS(i,j);52 }53 }54 Solve();55 }

 

 

 

转载于:https://www.cnblogs.com/zgglj-com/p/7695268.html

你可能感兴趣的文章
Cortex-M3开发经验(二):确定发生HardFault的地方
查看>>
testng入门教程11 TestNG运行JUnit测试
查看>>
FloatHelper
查看>>
异常处理
查看>>
分布式架构高可用架构篇_02_activemq高可用集群(zookeeper+leveldb)安装、配置、高可用测试...
查看>>
ORA-12560:TNS:协议适配器错误
查看>>
大数据量,海量数据 处理方法
查看>>
面向对象基础部分及模块
查看>>
less使用方法
查看>>
C#生成exe、dll版本号自动增加
查看>>
高效代码指泛型代替非泛型
查看>>
递归函数、匿名函数、内置函数
查看>>
第三周学习总结
查看>>
作业二:源程序版本管理软件和项目管理软件的优缺点
查看>>
jquery的DataTables插件的使用方法
查看>>
合并果子 2004年NOIP全国联赛普及组
查看>>
九度1457...
查看>>
重新开始学习javase_Exception
查看>>
排序命令sort
查看>>
Raspberry Pi开发之旅-同步时间
查看>>