题目链接:http://codeforces.com/problemset/problem/847/I

I. Noise Level
time limit per test

5 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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 2·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 nmq 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.

Examples
input
  1. 3 3 100 140
    ...
    A*.
    .B.
output
  1. 3
input
  1. 3 3 2 8
    B*.
    BB*
    BBB
output
  1. 4
input
  1. 3 4 5 4
    ..*B
    ..**
    D...
output
  1. 7
Note

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

题解:从每个噪音源点bfs(),然后统计值就可以

  1. #include<bits/stdc++.h>
  2. #define pb push
  3. #define ll long long
  4. #define PI 3.14159265
  5. using namespace std;
  6. const int maxn=;
  7. const int inf=0x3f3f3f3f;
  8. ll n,m,q,p;
  9. bool vis[maxn][maxn];
  10. char mp[maxn][maxn];
  11. int sd[maxn][maxn];
  12. int dx[]={-,,,};
  13. int dy[]={,,-,};
  14. struct node
  15. {
  16. int x,y,z;
  17. };
  18. void bfs(int x,int y)
  19. {
  20. node a,next;
  21. a.x=x;a.y=y;a.z=(mp[x][y]-'A'+)*q;
  22. queue<node>qq;
  23. qq.pb(a);
  24. sd[x][y]+=a.z;
  25. memset(vis,false,sizeof(vis));
  26. vis[x][y]=true;
  27. while(!qq.empty())
  28. {
  29. a=qq.front();
  30. qq.pop();
  31. // if(a.z<=0)continue;
  32. for(int i=;i<;i++)
  33. {
  34. next.x=a.x+dx[i];
  35. next.y=a.y+dy[i];
  36. next.z=a.z/;
  37. if(next.x<||next.x>n||next.y<||next.y>m||mp[next.x][next.y]=='*'||vis[next.x][next.y])continue;
  38. vis[next.x][next.y]=true;
  39. sd[next.x][next.y]+=next.z;
  40. if(next.z>)qq.pb(next);
  41. }
  42. }
  43. }
  44. int main()
  45. {
  46. std::ios::sync_with_stdio(false);
  47. cin.tie();
  48. cout.tie();
  49. cin>>n>>m>>q>>p;
  50. for(int i=;i<=n;i++)
  51. {
  52. for(int j=;j<=m;j++)
  53. {
  54. cin>>mp[i][j];
  55. }
  56. }
  57. for(int i=;i<=n;i++)
  58. {
  59. for(int j=;j<=m;j++)
  60. {
  61. if(mp[i][j]>='A'&&mp[i][j]<='Z')
  62. {
  63. bfs(i,j);
  64. }
  65. }
  66. }
  67.  
  68. int ans=;
  69. for(int i=;i<=n;i++)
  70. {
  71. for(int j=;j<=m;j++)
  72. {
  73. if(sd[i][j]>p)ans++;
  74. }
  75. }
  76. cout<<ans<<endl;
  77. return ;
  78. }

2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest, qualification stage (Online Mirror, ACM-ICPC Rules, Teams Preferred)的更多相关文章

  1. D. Dog Show 2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest, qualification stage (Online Mirror, ACM-ICPC Rules, Teams Preferred)

    http://codeforces.com/contest/847/problem/D 巧妙的贪心 仔细琢磨... 像凸包里的处理 #include <cstdio> #include & ...

  2. 2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest, qualification stage

    2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest, qualification stage A. Union of Doubly Link ...

  3. 2018-2019 ACM-ICPC, NEERC, Southern Subregional Contest, Qualification Stage(11/12)

    2018-2019 ACM-ICPC, NEERC, Southern Subregional Contest, Qualification Stage A. Coffee Break 排序之后优先队 ...

  4. 2019.04.18 第六次训练 【2018-2019 ACM-ICPC, NEERC, Southern Subregional Contest, Qualification Stage】

    题目链接: https://codeforces.com/gym/101911 又补了set的一个知识点,erase(it)之后it这个地址就不存在了,再引用的话就会RE A: ✅ B:  ✅ C: ...

  5. 2018-2019 ICPC, NEERC, Southern Subregional Contest

    目录 2018-2019 ICPC, NEERC, Southern Subregional Contest (Codeforces 1070) A.Find a Number(BFS) C.Clou ...

  6. Codeforces 2018-2019 ICPC, NEERC, Southern Subregional Contest

    2018-2019 ICPC, NEERC, Southern Subregional Contest 闲谈: 被操哥和男神带飞的一场ACM,第一把做了这么多题,荣幸成为7题队,虽然比赛的时候频频出锅 ...

  7. 2018.10.20 2018-2019 ICPC,NEERC,Southern Subregional Contest(Online Mirror, ACM-ICPC Rules)

    i207M的“怕不是一个小时就要弃疗的flag”并没有生效,这次居然写到了最后,好评=.= 然而可能是退役前和i207M的最后一场比赛了TAT 不过打得真的好爽啊QAQ 最终结果: 看见那几个罚时没, ...

  8. 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror) Solution

    从这里开始 题目列表 瞎扯 Problem A Find a Number Problem B Berkomnadzor Problem C Cloud Computing Problem D Gar ...

  9. Codeforces1070 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)总结

    第一次打ACM比赛,和yyf两个人一起搞事情 感觉被两个学长队暴打的好惨啊 然后我一直做傻子题,yyf一直在切神仙题 然后放一波题解(部分) A. Find a Number LINK 题目大意 给你 ...

随机推荐

  1. 查询session内容

    Enumeration enumsession = request.getSession().getAttributeNames(); while(enumsession.hasMoreElement ...

  2. 安装mariadb二进制程序

    author:JevonWei 版权声明:原创作品 下载mariadb软件包 https://downloads.mariadb.org/mariadb/5.5.57/ 一.创建用户和准备数据目录 1 ...

  3. struts.xml如何加载到及配置问题

    今天项目做客户化处理,看到struts.xml,突然间想不起来这个文件从哪里加载的了,真是越学越回去了.这里记录下. web工程启动的时候,系统会加载web.xml文件,在这个时候会加载Spring的 ...

  4. Qt--自定义Model

    众所周知,Qt提供了一套Model/View框架供开发者使用,Model用来提供数据, View则用来提供视觉层的显示.实际上这是一套遵循MVC设计模式的GUI框架,因为Qt还提供了默认的Delega ...

  5. 微软为啥让免费升Win10?

           今天终于赶在截止日期之前把我的联想PC升到win10.微软这次对中国开放的持续一年的免费升级活动主要有两个原因.首先当然是"感恩Windows用户长久支持的回馈".微 ...

  6. 自制STP配置实验

    本图使用Gns模拟器 实验需求: 1.要求利用vtp实现vlan同步设置 2.要求vtp server实现备份冗余 3.创建vlan 1~10要求MLSW1 是奇数vlan主根 MLSW2 是偶数vl ...

  7. Spring mybatis源码篇章-XMLLanguageDriver解析sql包装为SqlSource

    前言:通过阅读源码对实现机制进行了解有利于陶冶情操,承接前文Spring mybatis源码篇章-MybatisDAO文件解析(二) 首先了解下sql mapper的动态sql语法 具体的动态sql的 ...

  8. 集美大学网络1413第十五次作业成绩(团队十) -- 项目复审与事后分析(Beta版本)

    题目 团队作业10--项目复审与事后分析(Beta版本) 团队作业10成绩 --团队作业10-1 Beta事后诸葛亮  团队/分值 设想和目标 计划 资源 变更管理 设计/实现 测试/发布 团队的角色 ...

  9. C语言中变量的作用域和生命周期

    变量的类型: 1. 局部变量和全局变量 局部变量也称为内部变量. 局部变量是在函数内作定义说明的.其作用域仅限于函数内, 离开该函数后再 使用这种变量是非法的. 全局变量也称为外部变量,它是在函数外部 ...

  10. 201521123011 《Java程序设计》 第三周学习总结

    1. 本周学习总结 2. 书面作业 1.代码阅读 public class Test1 { private int i = 1;//这行不能修改 private static int j = 2; p ...